What is the difference between the selectitem and selectitems tags in jsf?
The difference is exactly what you would expect. The selectitem
tag adds a single item to the HTML list while selectitems
adds multiple items.
From http://www.jsftoolbox.com/documentation/help/12-TagReference/core/f_selectItem.html:
SelectItem:
The SelectItem
tag adds a child UISelectItem
component to the component associated with the enclosing tag. In the HTML renderkit, this creates a single element. It can be used with any of the select tags in the JSF HTML tag library. The body content of this tag must be empty.
Example:
<h:selectOneMenu id="list1">
<f:selectItem itemLabel="Option 1" itemValue="1"></f:selectItem>
</h:selectOneMenu>
HTML Output:
<select id="list1" name="list1" size="1">
<option value="1">Option 1</option>
</select>
SelectItems:
The SelectItems
tag adds a child UISelectItems
component to the component associated with enclosing tag. You can use this tag to set a list of objects in your domain model as the options for a select component. The body content of this tag must be empty.
Example:
<h:selectManyListbox id="list">
<f:selectItems value="#{optionBean.optionList}"></f:selectItem>
</h:selectManyListbox>
HTML Output:
<select id="list" name="list" multiple="true" size="-2147483648">
<option value="1">Option 1</option>
<option value="2">Option 2</option>
<option value="3">Option 3</option>
</select>
Its also nice to remember that the f:selectItems can point to a SelectItem, an array or Collection of SelectItem objects, or a Map mapping labels to values.