10.12.2012 Views

The Java EE 5 Tutorial (PDF) - Oracle Software Downloads

The Java EE 5 Tutorial (PDF) - Oracle Software Downloads

The Java EE 5 Tutorial (PDF) - Oracle Software Downloads

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Using Localized Data<br />

style="color: red;<br />

font-family: ’New Century Schoolbook’, serif;<br />

font-style: oblique;<br />

text-decoration: overline" id="errors1" for="userNo"/><br />

<strong>The</strong> for attribute refers to the ID of the component that generated the error message. <strong>The</strong> error<br />

message is displayed at the same location that the message tag appears in the page. In this case,<br />

the error message will appear after the Submit button.<br />

<strong>The</strong> style attribute allows you to specify the style of the text of the message. In the example in<br />

this section, the text will be red, New Century Schoolbook, serif font family, and oblique style,<br />

and a line will appear over the text. <strong>The</strong> message and messages tags support many other<br />

attributes for defining styles. Please refer to the TLD documentation for more information on<br />

these attributes.<br />

Another attribute the messages tag supports is the layout attribute. Its default value is list,<br />

which indicates that the messages are displayed in a bulleted list using the HTML ul and li<br />

elements. If you set the attribute to table, the messages will be rendered in a table using the<br />

HTML table element.<br />

<strong>The</strong> preceding example shows a standard validator is registered on input component. <strong>The</strong><br />

message tag displays the error message associated with this validator when the validator cannot<br />

validate the input component’s value. In general, when you register a converter or validator on a<br />

component, you are queueing the error messages associated with the converter or validator on<br />

the component. <strong>The</strong> message and messages tags display the appropriate error messages that are<br />

queued on the component when the validators or converters registered on that component fail<br />

to convert or validate the component’s value.<br />

All the standard error messages that come with the standard converters and validators are listed<br />

in section 2.5.4 of the <strong>Java</strong>Server Faces specification. An application architect can override these<br />

standard messages and supply error messages for custom converters and validators by<br />

registering custom error messages with the application by means of the message-bundle<br />

element of the application configuration file. “Referencing Error Messages” on page 350<br />

explains more about error messages.<br />

Using Localized Data<br />

348<br />

<strong>Java</strong>Server Faces applications make use of three different kinds of data that can be localized:<br />

■ Static text, such as labels, alternative text, and tool tips<br />

■ Error messages, such as those displayed when validation of user input data fails<br />

■ Dynamic data, which is data that must be set dynamically by server-side objects, such as by<br />

backing beans<br />

This section discusses how to access the first two kinds of data from the page. “Performing<br />

Localization” on page 388 explains how to produce localized error messages as well as how to<br />

<strong>The</strong> <strong>Java</strong> <strong>EE</strong> 5<strong>Tutorial</strong> • June 2010

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!