background image

The message Tag

<< The UISelectMany Component | Using Localized Data >>
<< The UISelectMany Component | Using Localized Data >>

The message Tag

"UISelectItems Properties" on page 385
describes in more detail how to write a backing bean
property for a UISelectItems component.
Using the selectItem Tag
The selectItem tag represents a single item in a list of items. Here is the example from
"Displaying a Menu Using the selectOneMenu Tag" on page 344
:
<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>
The itemValue attribute represents the default value of the SelectItem instance. The
itemLabel
attribute represents the String that appears in the drop-down menu component on
the page.
The itemValue and itemLabel attributes are value-binding-enabled, meaning that they can use
value-binding expressions to refer to values in external objects. They can also define literal
values, as shown in the example selectOneMenu tag.
Displaying Error Messages with the message and
messages
Tags
The message and messages tags are used to display error messages when conversion or
validation fails. The message tag displays error messages related to a specific input component,
whereas the messages tag displays the error messages for the entire page.
Here is an example message tag from the guessNumber application, discussed in
"Steps in the
Development Process" on page 288
:
<h:inputText id=
"userNo" value="#{UserNumberBean.userNumber}">
<f:validateLongRange minimum=
"0" maximum="10" />
<h:commandButton id=
"submit"
action=
"success" value="Submit" /><p>
<h:message
Adding UI Components to a Page Using the HTML Component Tags
Chapter 11 · Using JavaServer Faces Technology in JSP Pages
349