|Red Hat Web Application Framework 6.1: WAF Developer Guide|
|Prev||Chapter 13. Web Applications Tutorial||Next|
When a user requests a URL, the server determines the appropriate Locale for the request. It does this by negotiating between the client's preferences and the server's capabilities.
All valid URLs on the server are associated with an instance of some application.
If that application instance has an associated Locale, this will be used as the Locale for the request. If the application instance does not have an associated Locale, the server checks whether the user has a preferred Locale as kept by the WAF preferences service.
If there is a preferred Locale, and if that Locale is supported by the application, that is the chosen Locale for the request.
If there is not a preferred Locale the server continues on to check the Accept-Language HTTP headers. Checking each of the values in this HTTP header in order of descending q-value, the server selects the first one that is supported by the application being served.
If no Locale can be determined, the server finally selects the default Locale for the server as the Locale for the request. This algorithm is well documented in the LocaleNegotiator class.
This negotiation allows applications to support one or many languages without interacting with other applications on the system. Thus, your application automatically tries to present itself to the user in his or her preferred language, regardless of the other applications running on that server.
If an application built on WAF relies on a service provided by another package, that package must also be globalized and must support any languages the WAF application is intended to support.
For example, if your application relies on the places service to relate and/or present geographical data, you must ensure that this service supports all the Locales that you wish your application to support.
You can retrieve the Locale for the current request by calling the getLocale() method of the current RequestContext. For example:
java.util.Locale locale = DispatcherHelper.getRequestContext(request).getLocale(); System.out.println("The locale for the current request is: " + locale.toString());
Another option, character set encoding negotiation (charset negotiation) is more complicated than Locale negotiation.