background image

Referencing Localized Static Data

<< Loading a Resource Bundle | The requiredMessage Attribute >>
<< Loading a Resource Bundle | The requiredMessage Attribute >>

Referencing Localized Static Data

referencing the error messages from the input component attributes described in
"Referencing
Error Messages" on page 352
. In that case, you load the resource bundles containing these
messages in the same way you load resource bundles containing static text.
Referencing Localized Static Data
To reference static localized data from a resource bundle, you use a value expression from an
attribute of the component tag that will display the localized data. You can reference the
message from any component tag attribute that is enabled to accept value expressions.
The value expression has the notation var.message, in which var matches the var attribute of
the loadBundle tag or the var element in 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 bookstore.jsp:
<h:outputText value=
"#{bundle.Talk}"/>
Notice that bundle matches the var attribute from the loadBundle tag and that Talk matches
the key in the ResourceBundle.
Another example is the graphicImage tag from chooselocale.jsp:
<h:graphicImage id=
"mapImage" url="/template/world.jpg"
alt=
"#{bundle.ChooseLocale}"
usemap=
"#worldMap" />
The alt attribute is enabled to accept value expressions. In this case, the alt attribute refers to
localized text that will be included in the alternative text of the image rendered by this tag.
See
"Creating Custom Component Classes" on page 419
and
"Enabling Component Properties
to Accept Expressions" on page 424
for information on how to enable value binding on your
custom component's attributes.
Referencing Error Messages
A JavaServer Faces page uses the message or messages tags to access error messages, as
explained in
"Displaying Error Messages with the message and messages Tags" on page 349
.
Using Localized Data
The Java EE 5 Tutorial · September 2007
352