A custom tag that creates an select element from an enumeration

How can I create a tag that makes a selection box from a Java enumeration for Play! framework? I tried to understand how the CRUD module works, but there are too many layers of abstraction that I do not understand yet.

+3
source share
2 answers

If you fully qualify Enum in a tag, you do not need to place it in RenderArgs.

Your StatusSelect.html tag:

<select name="status">
    #{list com.something.StatusEnum.values(), as:'status'}
        <option>${status}</option>
    #{/list}
</select>

And called from the page:

#{StatusSelect /}

Then you can add complexity to it by specifying the name attribute and other functions, for example:

<select id="${_id}" name="${_name}" class="${_class}">
    #{list com.something.StatusEnum.values(), as:'status'}
        <option>${status}</option>
    #{/list}
</select>

And the new page tag:

#{StatusSelect id:'status1', name:'status', class:'bold'/}
+4
source

Damo enums, # {select} -tag .

0

Source: https://habr.com/ru/post/1772731/


All Articles