background image

The selectOneMenu Tag

<< Rendering Components for Selecting OneValue | Rendering Components for Selecting Multiple Values >>
<< Rendering Components for Selecting OneValue | Rendering Components for Selecting Multiple Values >>

The selectOneMenu Tag

<h:selectBooleanCheckbox
id=
"fanClub"
rendered=
"false"
binding=
"#{cashier.specialOffer}" />
<h:outputLabel
for=
"fanClub"
rendered=
"false"
binding=
"#{cashier.specialOfferText}">
<h:outputText
id=
"fanClubLabel"
value=
"#{bundle.DukeFanClub}" />
</h:outputLabel>
This example tag displays a check box to allow users to indicate whether they want to join the
Duke Fan Club. The label for the check box is rendered by the outputLabel tag. The actual text
is represented by the nested outputText tag.
"Binding a Component Instance to a Bean
Property" on page 368
discusses this example in more detail.
Displaying a Menu Using the selectOneMenu Tag
A UISelectOne component allows the user to select one value from a set of values. This
component can be rendered as a list box, a set of radio buttons, or a menu. This section explains
the selectOneMenu tag. The selectOneRadio and selectOneListbox tags are written in a
similar way. The selectOneListbox tag is similar to the selectOneMenu tag except that
selectOneListbox
defines a size attribute that determines how many of the items are
displayed at once.
The selectOneMenu tag represents a component that contains a list of items, from which a user
can choose one item. The menu is also commonly known as a drop-down list or a combo box.
The following code snippet shows the selectOneMenu tag from the bookcashier.jsp page of
the Duke's Bookstore application. This tag allows the user to select a shipping method:
<h:selectOneMenu
id=
"shippingOption"
required=
"true"
value=
"#{cashier.shippingOption}">
<f:selectItem
itemValue=
"2"
itemLabel=
"#{bundle.QuickShip}"/>
<f:selectItem
itemValue=
"5"
itemLabel=
"#{bundle.NormalShip}"/>
<f:selectItem
itemValue=
"7"
itemLabel=
"#{bundle.SaverShip}"/>
</h:selectOneMenu>
Adding UI Components to a Page Using the HTML Component Tags
The Java EE 5 Tutorial · September 2007
344