background image

Rendering Components for Selecting Multiple Values

<< The selectOneMenu Tag | The UISelectItem Component >>
<< The selectOneMenu Tag | The UISelectItem Component >>

Rendering Components for Selecting Multiple Values

The value attribute of the selectOneMenu tag maps to the property that holds the currently
selected item's value. You are not required to provide a value for the currently selected item. If
you don't provide a value, the first item in the list is selected by default.
Like the selectOneRadio tag, the selectOneMenu tag must contain either a selectItems tag or
a set of selectItem tags for representing the items in the list.
"The UISelectItem,
UISelectItems
, and UISelectItemGroup Components" on page 346
explains these tags.
Rendering Components for Selecting Multiple Values
In some cases, you need to allow your users to select multiple values rather than just one value
from a list of choices. You can do this using one of the following kinds of components:
A set of check boxes
A drop-down menu
A list box
Figure 11­5
shows examples of these components.
The UISelectMany class defines a component that allows the user to select zero or more values
from a set of values. This component can be rendered as a set of check boxes, a list box, or a
menu. This section explains the selectManyCheckbox tag. The selectManyListbox tag and
selectManyMenu
tag are written in a similar way.
A list box differs from a menu in that it displays a subset of items in a box, whereas a menu
displays only one item at a time when the user is not selecting the menu. The size attribute of
the selectManyListbox tag determines the number of items displayed at one time. The list box
includes a scroll bar for scrolling through any remaining items in the list.
The selectManyCheckbox tag renders a set of check boxes, with each check box representing
one value that can be selected. Duke's Bookstore uses a selectManyCheckbox tag on the
bookcashier.jsp
page to allow the user to subscribe to one or more newsletters:
FIGURE 11­5
Example Select Many Components
Adding UI Components to a Page Using the HTML Component Tags
Chapter 11 · Using JavaServer Faces Technology in JSP Pages
345