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 JSF Core Tag Reference:
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>
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With