Download
FAQ
History
PrevHomeNext API
Search
Feedback
Divider

Internationalization

The application client and Web client distributed with the Duke's Bank application are internationalized. All strings that appear in the user interfaces are retrieved from resource bundles. The administration client uses resource bundles named AdminMessages_*.properties. The Web client uses resource bundles named WebMessages_*.properties. Both clients are distributed with English and Spanish resource bundles.

The application client retrieves locale information from the command line. For example, to use the Spanish resource bundle, invoke the application this way:

appclient -client DukesBankAppClient.jar es 

The administration client class BankAdmin creates a ResourceBundle that has a locale created from the command-line arguments:

//Constructor
public BankAdmin(Locale currentLocale) {
  //Internationalization setup
  messages = ResourceBundle.getBundle("AdminMessages",
    currentLocale); 

The Web client Dispatcher component retrieves the locale (set by a browser language preference) from the request, opens the resource bundle, and then saves the bundle as a session attribute:

ResourceBundle messages = (ResourceBundle)session.
  getAttribute("messages");
  if (messages == null) {
    Locale locale=request.getLocale();
    messages = ResourceBundle.getBundle("WebMessages",
      locale); 
    session.setAttribute("messages", messages);
  } 

The Web client's JavaBeans components access localized messages using messages.getString("key");.

The Web client's JSP pages use the JSTL fmt:message tags to retrieve localized messages. You set the localization context of the JSTL fmt tag library as a context parameter when you package the Web client with deploytool.

For example, here is how accountHist.jsp generates the headings for the transactions table:

<td><center><b><fmt:message 
  key="TxDate"/></b></center></td>
<td><center><b><fmt:message
  key="TxDescription"/></center></b></td>
<td><center><b><fmt:message 
  key="TxAmount"/></b></center></td>
<td><center><b><fmt:message
  key="TxRunningBalance"/></b></center></td> 
Divider
Download
FAQ
History
PrevHomeNext API
Search
Feedback
Divider

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.