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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

style="color: red;<br />

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

For more information on using the message or messages tags, see “Displaying Error Messages<br />

with the message and messages Tags” on page 347.<br />

Messages that are not queued on a component and are therefore not loaded automatically are<br />

referenced using a value expression. You can reference a localized message from almost any<br />

<strong>Java</strong>Server Faces tag attribute.<br />

<strong>The</strong> value expression that references a message has the same notation whether you loaded the<br />

resource bundle with the loadBundle tag or registered it with the resource-bundle element in<br />

the configuration file.<br />

<strong>The</strong> value expression notation is var.message, in which var matches the var attribute of the<br />

loadBundle tag or the var element defined in the resource-bundle element of the<br />

configuration file, and message matches the key of the message contained in the resource<br />

bundle, referred to by the var attribute.<br />

Here is an example from bookstore.jsp:<br />

<br />

Notice that bundle matches the var attribute from the loadBundle tag and that Talk matches<br />

the key in the resource bundle.<br />

For information on using localized messages in <strong>Java</strong>Server Faces, see “Rendering Components<br />

for Selecting Multiple Values” on page 343.<br />

Date and Number Formatting<br />

<strong>Java</strong> programs use the DateFormat.getDateInstance(int, locale) to parse and format dates<br />

in a locale-sensitive manner. <strong>Java</strong> programs use the NumberFormat.getXXXInstance(locale)<br />

method, where XXX can be Currency, Number,orPercent, to parse and format numerical<br />

values in a locale-sensitive manner. <strong>The</strong> servlet version of Duke’s Bookstore uses the currency<br />

version of this method to format book prices.<br />

JSTL applications use the fmt:formatDate and fmt:parseDate tags to handle localized dates<br />

and use the fmt:formatNumber and fmt:parseNumber tags to handle localized numbers,<br />

including currency values. For information on the JSTL formatting tags, see “Formatting Tags”<br />

on page 215. <strong>The</strong> JSTL version of Duke’s bookstore uses the fmt:formatNumber tag to format<br />

book prices and the fmt:formatDate tag to format the ship date for an order:<br />

.<br />

Date and Number Formatting<br />

Chapter 15 • Internationalizing and LocalizingWeb Applications 469

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

Saved successfully!

Ooh no, something went wrong!