Download
FAQ History |
API
Search Feedback |
Using Localized Messages
All data and messages in the Duke's Bookstore application have been completely localized for Spanish, French, German, and American English. Performing Localization explains how to produce the localized messages as well as how to localize dynamic data and messages.
The image map on the first page allows you to select your preferred locale. See Chapter 20 for information on how the image map custom component was created.
This section explains how to use localized static data and messages for JavaServer Faces applications. If you are not familiar with the basics of localizing Web applications, see Chapter 22. Localized static data can be included in a page by using the
loadBundle
tag, defined injsf_core.tld
. Follow these steps:A
ResourceBundle
contains a set of localized messages. For more information about resource bundles, seeAfter the application developer has produced a
ResourceBundle
, the application architect puts it in the same directory as the application classes. Much of the data for the Duke's Bookstore application is stored in aResourceBundle
calledBookstoreMessages
.Referencing a ResourceBundle from a Page
For a page with JavaServer Faces tags to use the localized messages contained in a
ResourceBundle
, the page must reference theResourceBundle
using aloadBundle
tag.The
loadBundle
tag frombookstore.jsp
isThe
basename
attribute value refers to theResourceBundle
, located in themessages
package of thebookstore
application. Make sure that thebasename
attribute specifies the fully qualified class name of the file.The
var
attribute is an alias to theResourceBundle
. This alias can be used by other tags in the page in order to access the localized messages.Referencing a Localized Message
To reference a localized message from a
ResourceBundle
, you use a value-binding expression from an attribute of the component tag that will display the localized data. You can reference the message from any component tag attribute that is value-binding-enabled.The value-binding expression has the notation "
var.message
", in whichvar
matches thevar
attribute of theloadBundle
tag, andmessage
matches the key of the message contained in theResourceBundle
referred to by thevar
attribute. Here is an example frombookstore.jsp
:Notice that
bundle
matches thevar
attribute from theloadBundle
tag and thatTalk
matches the key in theResourceBundle
.Another example is the
graphicImage
tag fromchooseLocale.jsp
:<h:graphicImage id="mapImage" url="/template/world.jpg" alt="#{bundle.chooseLocale}" usemap="#worldMap" />The
alt
attribute is value-binding-enabled, and this means that it can use value-binding expressions. In this case, thealt
attribute refers to localized text, which will be included in thealt
text of the image rendered by this tag.See Creating the Component Tag Handler and Enabling Value-Binding of Component Properties for information on how to enable value binding on your custom component's attributes.
Download
FAQ History |
API
Search Feedback |
All of the material in The J2EE(TM) 1.4 Tutorial is copyright-protected and may not be published in other works without express written permission from Sun Microsystems.