J F W

making web application programming easier is possible

HOW TO : CORE

Multi language support

All Struts modules are compatible with a multi language project. JFW offers a little more to make the use of the various locales simpler in actions .

The method used for managing the locales is initLocale. This method sets the locale based on this logic:

  1. If a parameter with name LOCALE_KEY exists in request then the value of this parameter is used to set the locale. The value of the parameters is a language as defined here (ISO 639-1).
  2. If exists in session, an attribute under key LOCALE_KEY then the locale is already set and nothing more must be done.
  3. If cookie jfw_locale exists in request then the value in the cookie is used.
  4. If key default_language is defined in jfw.properties then this value is used. To get the default application locale, the method getLocale of class com.jfw.util.JFWLocale is used.
  5. If all other methods failed, the getLocale method of Struts is called.
The first successful step of the previous steps sets the locale and stops the process. Setting the locale is a multistep process:
  1. Call Struts method Action.setLocale(request, locale).
  2. Add a Locale object in HttpSession under key LOCALE_KEY.
  3. Set a cookie with name jfw_locale and value the locale data.
So, when the get locale methods ( getLocale or getLocaleLanguage ) are used, the locale already set in HttpSession is returned.

You can see an example of how to change the locale in file home.jsp; see how the parameter LANGUAGE_KEY in the form with name lang_form is valorized.