7.3 Localization Contexts

   

As "Localizing Messages" on page 251 illustrated , <fmt:message> actions retrieve localized messages from a resource bundle. That resource bundle and the locale that was used to locate it are stored in a localization context, which is a simple bean that maintains a reference to a resource bundle and a locale. The <fmt:message> actions use the localization context's resource bundle, and the JSTL formatting actions use its locale. [5]

[5] See "Formatting Actions" on page 308 for more information about formatting actions.

All of the examples in "Localizing Messages" on page 251 establish a localization context with a combination of <fmt:setLocale> and <fmt:setBundle> actions, for example:

 <fmt:setLocale value='en-US'/>  <fmt:setBundle basename='messages'/> ... <fmt:message key='someKey'/> 

In the preceding code fragment, the <fmt:setLocale> action stores the U.S. English locale in a configuration setting named FMT_LOCALE . [6] Subsequently, the <fmt:setBundle> action performs a resource bundle lookup ”see "Resource Bundle Lookup" on page 274 for the exact details of that lookup ”using the locale stored in the FMT_LOCALE configuration setting and the resource bundle base name specified with the basename attribute. If that lookup was successful, <fmt:setBundle> stores the resource bundle and the locale that was used to locate it in a localization context and stores that localization context in a configuration setting named FMT_LOCALIZATION_CONTEXT . Subsequently, the <fmt:message> action uses the resource bundle stored in the localization context that <fmt:setBundle> stored in the FMT_LOCALIZATION_CONTEXT configuration setting.

[6] See "Configuration Settings" on page 230 for more information about configuration settings.

All <fmt:message> actions use the (resource bundle stored in the) localization context stored in the FMT_LOCALIZATION_CONTEXT configuration setting to retrieve localized messages, except for <fmt:message> actions that are nested in <fmt:bundle> actions, like this:

 <fmt:bundle basename='app'>     <%-- The following <fmt:message> action uses the localization    context created by the enclosing <fmt:bundle> action --%>    <fmt:message key='someKey'/> </fmt:bundle> 

The <fmt:bundle> action creates a localization context that is used exclusively by <fmt:message> actions and formatting actions that are nested in the <fmt:bundle> action. That localization context temporarily overrides the localization context stored in the FMT_LOCALIZATION_CONTEXT configuration setting.

Now that we understand what a localization context is and how it's created and used by the I18N actions, let's take a closer look at those actions.

   


Core JSTL[c] Mastering the JSP Standard Tag Library
Core JSTL[c] Mastering the JSP Standard Tag Library
ISBN: 131001531
EAN: N/A
Year: 2005
Pages: 124

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net