JSF selectItem Tag

In this section you will learn about the selectItem tag. It can be used with any select tag of JSF html tag library.

JSF selectItem Tag


This tag is used to add a child component to the component associated with the enclosing tag. In this section you will learn about the selectItem tag. It can be used with any select tag of JSF html tag library. It renders "option" element when converted to html. In the example below selectItem tag has been used within selectManyListbox tag. So these are the child components of List Box component and these child components provides options for the List Box component. 

Code Description :

<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>

<h:outputText value="Select windows to open"/><br><br>
<h:selectManyListbox id="subscriptions" value="#{TableBean.perInfoAll}" size="3">
<f:selectItem id="si1" itemLabel="window1" itemValue="w1" />
<f:selectItem id="si2" itemLabel="window2" itemValue="w2" />
<f:selectItem id="si3" itemLabel="window3" itemValue="w3" />
<f:selectItem id="si4" itemLabel="window4" itemValue="w4" />
<f:selectItem id="si5" itemLabel="window5" itemValue="w5" />
<f:selectItem id="si6" itemLabel="window6" itemValue="w6" />


Rendered Output :

Html Source Code :

<form id="_id0" method="post" action="/coretag/pages/selectItem.jsf" enctype="application/x-www-form-urlencoded">

Select windows to open<br><br>
<select id="_id0:subscriptions" name="_id0:subscriptions" multiple size="3"> 

<option value="w1">window1</option>
<option value="w2">window2</option>
<option value="w3">window3</option>
<option value="w4">window4</option>
<option value="w5">window5</option>
<option value="w6">window6</option>

<input type="hidden" name="_id0" value="_id0" /></form>


This tag contains some attributes :

id : This is used to uniquely identify the table component. This must be unique within the closest parent component.
binding : It is a value binding expression that is used to link component to a property in a backing bean.
itemLabel : This is used to set the label for the option rendered by this tag.
itemValue : This is used to set the value for the option rendered by this tag. This value is used at server when option is selected.
value : This is the value binding expression that indicates to the selectItem instance which contains the information about the option.
itemDescription : It is used to describe something about this option for your own purpose.
itemDisabled : This is a boolean attribute and is used to make the option enable or disable when it is set to "true" and "false" respectively. Its default value is "false".