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.

Providing Localized Messages and Labels<br />

468<br />

For more information on using this element, see “Registering Custom Error Messages” on<br />

page 445.<br />

Resource bundles containing messages that are explicitly referenced from a <strong>Java</strong>Server Faces tag<br />

attribute using a value expression must be registered using the resource-bundle element of the<br />

configuration file:<br />

<br />

com.sun.bookstore6.resources.CustomMessages<br />

customMessages<br />

<br />

For more information on using this element, see “Registering Custom Localized Static Text” on<br />

page 446<br />

Retrieving Localized Messages<br />

A web component written in the <strong>Java</strong> programming language retrieves the resource bundle<br />

from the session:<br />

ResourceBundle messages = (ResourceBundle)session.getAttribute("messages");<br />

<strong>The</strong>n it looks up the string associated with the key Talk as follows:<br />

messages.getString("Talk");<br />

<strong>The</strong> JSP versions of the Duke’s Bookstore application uses the fmt:message tag to provide<br />

localized strings for messages, HTML link text, button labels, and error messages:<br />

<br />

For information on the JSTL messaging tags, see “Messaging Tags” on page 214.<br />

<strong>The</strong> <strong>Java</strong>Server Faces version of Duke’s Bookstore retrieves messages using either the message<br />

or messages tag, or by referencing the message from a tag attribute using a value expression.<br />

You can only use a message or messages tag to display messages that are queued onto a<br />

component as a result of a converter or validator being registered on the component. <strong>The</strong><br />

following example shows a message tag that displays the error message queued on the userNo<br />

input component if the validator registered on the component fails to validate the value the user<br />

enters into the component.<br />

<br />

<br />

...<br />

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

Saved successfully!

Ooh no, something went wrong!