Java Reference
In-Depth Information
ResourceBundle messages = (Re-
sourceBundle)session.getAttribute("messages");
Then it looks up the string associated with the key person.lastName as follows:
messages.getString("person.lastName");
You can only use a message or messages tag to display messages that are queued onto
a component as a result of a converter or validator being registered on the component. The
following example shows a message tag that displays the error message queued on the
userNo input component if the validator registered on the component fails to validate
the value the user enters into the component.
Click here to view code image
<h:inputText id="userNo" value="#{UserNumberBean.userNumber}">
<f:validateLongRange minimum="0" maximum="10" />
...
<h:message
style="color: red;
text-decoration: overline" id="errors1" for="userNo"/>
For more information on using the message or messages tags, see “Displaying Error
Messages with the h:message and h:messages Tags” in The Java EE 6 Tutorial: Basic
Concepts .
Messages that are not queued on a component and are therefore not loaded automatically
are referenced using a value expression. You can reference a localized message from al-
most any JavaServer Faces tag attribute.
The value expression that references a message has the same notation whether you loaded
the resource bundle with the f:loadBundle tag or registered it with the resource-
bundle element in the configuration file.
The value expression notation is var.message , in which var matches the var attrib-
ute of the f:loadBundle tag or the var element defined in the resource-bundle
element of the configuration file, and message matches the key of the message contained
in the resource bundle, referred to by the var attribute.
Here is an example from editAddress.xhtml in Duke's Tutoring:
<h:outputLabel for="country" value="#{bundle['address.country']}:"
/>
Search WWH ::




Custom Search