The RequestLocale component is stored for easy access in the requestLocale property of the DynamoHttpServletRequest object that is passed in each request. This section describes how to reference the RequestLocale, and it contains the following topics:

Getting the RequestLocale

The following is an example of getting and using the RequestLocale inside an Oracle ATG Web Commerce servlet bean or other servlet:

public void service (DynamoHttpServletRequest pRequest,
                     DynamoHttpServletResponse pResponse)
        throws IOException, ServletException
  RequestLocale reqLocale = null;
  Locale        locale    = null;

  // Make sure the RequestLocale isn't null...
  if ((reqLocale = pRequest.getRequestLocale()) != null) {
   // ...then get the Locale
   locale = reqLocale.getLocale();
  else {
   // Otherwise, just use the JVM's default Locale
   locale = Locale.getDefault();

  // Then you can use the locale to set up formatters; for instance...
  NumberFormat format = NumberFormat.getCurrencyInstance(locale);
  // ...etc....
Updating the RequestLocale

For performance reasons, the RequestLocale is created the first time it is needed in a session. The locale to use for a session is decided at the time of the RequestLocale creation. The Locale object stored in the RequestLocale component is not updated from request to request; it is updated only when the handleRefresh method is called to refresh the component. For example, the handleRefresh method is required when a visitor has changed the language of his or her session (via one of the sources in the RequestLocale hierarchy).

To make the RequestLocale component re-evaluate the Locale object being used, call the RequestLocale.handleRefresh() method. This method can be called from a JSP as follows:

<dsp:setvalue bean="/atg/dynamo/servlet/RequestLocale.refresh" value=" "/>

Note: Changes to a browser’s ACCEPT-LANGUAGE value are not detected unless the property RequestLocale.detectHTTPHeaderChanges is set to true.

After a session has ended, any information that the RequestLocale component provided for the session is stored in the locale property of the user’s profile.

If you want to update the RequestLocale immediately after a user has changed the locale on a profile form, you can design the updating form to set the ProfileFormHandler.updateSuccessURL to a success page as follows. For example:

<dsp:form action="<%=ServletUtil.getRequestURI(request)%>" method="POST">
<dsp:input bean="ProfileFormHandler.updateSuccessURL" type="HIDDEN"

The success page must then update the request URL by calling the RequestLocale.handleRefresh() method as shown above.