background image

Dates and Numbers Formatting

<< Retrieving Localized Messages | Character Sets and Encodings >>
<< Retrieving Localized Messages | Character Sets and Encodings >>

Dates and Numbers Formatting

style=
"color: red;
text-decoration: overline
" id="errors1" for="userNo"/>
For more information on using the message or messages tags, see
"Displaying Error Messages
with the message and messages Tags" on page 349
.
Messages that are not queued on a component and are therefore not loaded automatically are
referenced using a value expression. You can reference a localized message from almost any
JavaServer Faces tag attribute.
The value expression that references a message has the same notation whether you loaded the
resource bundle with the loadBundle tag or registered it with the resource-bundle element in
the configuration file.
The value expression notation is var.message, in which var matches the var attribute of the
loadBundle
tag or the var element defined in the resource-bundle element of 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 resource bundle.
For information on using localized messages in JavaServer Faces, see
"Rendering Components
for Selecting Multiple Values" on page 345
.
Date and Number Formatting
Java programs use the DateFormat.getDateInstance(int, locale) to parse and format dates
in a locale-sensitive manner. Java programs use the NumberFormat.getXXXInstance(locale)
method, where XXX can be Currency, Number, or Percent, to parse and format numerical
values in a locale-sensitive manner. The servlet version of Duke's Bookstore uses the currency
version of this method to format book prices.
JSTL applications use the fmt:formatDate and fmt:parseDate tags to handle localized dates
and use the fmt:formatNumber and fmt:parseNumber tags to handle localized numbers,
including currency values. For information on the JSTL formatting tags, see
"Formatting Tags"
on page 217
. The JSTL version of Duke's bookstore uses the fmt:formatNumber tag to format
book prices and the fmt:formatDate tag to format the ship date for an order:
<fmt:formatDate value=
"${shipDate}" type="date"
dateStyle=
"full"/>.
Date and Number Formatting
Chapter 15 · Internationalizing and Localizing Web Applications
471