background image

Using Localized Data

<< The message Tag | Loading a Resource Bundle >>
<< The message Tag | Loading a Resource Bundle >>

Using Localized Data

style=
"color: red;
font-family:
'New Century Schoolbook', serif;
font-style: oblique;
text-decoration: overline
" id="errors1" for="userNo"/>
The for attribute refers to the ID of the component that generated the error message. The error
message is displayed at the same location that the message tag appears in the page. In this case,
the error message will appear after the Submit button.
The style attribute allows you to specify the style of the text of the message. In the example in
this section, the text will be red, New Century Schoolbook, serif font family, and oblique style,
and a line will appear over the text. The message and messages tags support many other
attributes for defining styles. Please refer to the TLD documentation for more information on
these attributes.
Another attribute the messages tag supports is the layout attribute. Its default value is list,
which indicates that the messages are displayed in a bulleted list using the HTML ul and li
elements. If you set the attribute to table, the messages will be rendered in a table using the
HTML table element.
The preceding example shows a standard validator is registered on input component. The
message tag displays the error message associated with this validator when the validator cannot
validate the input component's value. In general, when you register a converter or validator on a
component, you are queueing the error messages associated with the converter or validator on
the component. The message and messages tags display the appropriate error messages that are
queued on the component when the validators or converters registered on that component fail
to convert or validate the component's value.
All the standard error messages that come with the standard converters and validators are listed
in section 2.5.4 of the JavaServer Faces specification. An application architect can override these
standard messages and supply error messages for custom converters and validators by
registering custom error messages with the application by means of the message-bundle
element of the application configuration file.
"Referencing Error Messages" on page 352
explains more about error messages.
Using Localized Data
JavaServer Faces applications make use of three different kinds of data that can be localized:
Static text, such as labels, alternative text, and tool tips
Error messages, such as those displayed when validation of user input data fails
Dynamic data, which is data that must be set dynamically by server-side objects, such as by
backing beans
This section discusses how to access the first two kinds of data from the page.
"Performing
Localization" on page 390
explains how to produce localized error messages as well as how to
Using Localized Data
The Java EE 5 Tutorial · September 2007
350