Select Tag

Suppose you have a java.util.Collection (i.e. List or Set) of Products, which you want to display in a combo box. If this list is available in any context as products, it could easily be browsed as:

Adding an empty line

In order to add an empty option, use the addEmpty attribute:

Setting the default selected item

You can set the selected item by specifying the selected attribute:

It will compare the selected attribute value with the id of each one of your products.

Showing radio buttons

A collection of radio buttons is just another output of a collection of elements. One can create radio buttons by using the type attribute:

Using tokens instead of collections

Sometimes one faces the problem of iterating over a small list of key, value pairs, instead of having one entire collection to iterate. The w:selectTokens tag works the same way as w:select, but instead of iterating over a collection, it uses a comma separated list of keys and values:

The above code will generate a combo box with items labeled 1, 2, ..., 7 and hidden values named first, second, ..., seventh.

The w:selectTokens tag does not contain an addEmpty attribute, nor the value one, which does not make sense in this case.