Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between selectitem and selectitems tags

Tags:

java

html

jsp

jsf

What is the difference between the selectitem and selectitems tags in jsf?

like image 672
Warrior Avatar asked Dec 01 '08 11:12

Warrior


1 Answers

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:

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>
like image 195
paxdiablo Avatar answered Oct 15 '22 13:10

paxdiablo