struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Craig R. McClanahan" <Craig.McClana...@eng.sun.com>
Subject Re: How come the user's Locale is stored in the Session?
Date Thu, 05 Oct 2000 20:23:37 GMT
Mike La Budde wrote:

> I noticed that the ActionServlet stores the user's Locale in the session.
> Presumably then all other code would do a
> session.getAttribute(Action.LOCALE_KEY) rather than a request.getLocale().
> Why is it done this way? (Performance?)
>

The original design intent was to deal with all three of the following
scenarios:

* The user has not (or does not know how to) configure
  their browser to send the right HTTP headers to select
  the locale that the user wants.

* The servlet container makes the wrong assumption about
  which Locale is desired.

* The user wants to be able to switch languages (and therefore
  Locales) in the middle of the application.

The third scenario is the most important of the three.

>
> Getting the Locale out of the request allows us developers to switch our
> language preference on the fly and view the same page in a different
> language. Storing it in the session forces us to log out before we will see
> it in a different language....
>

A patch was recently checked in to set the Locale in the session (based on the
value returned by the servlet container) if it is not there already.  This is
not in the 0.5 milestone release, but will be in 1.0.

If your application wants to support language switching on the fly, all you
have to do is replace the Locale object that is already there in an Action.
This is really simple to do:

    Locale newLocale = ... calculate new Locale value ...
    session.setAttribute(Action.LOCALE_KEY, newLocale);

You don't need to log out -- this will take effect the next time that you
forward to a JSP page that uses the locale-sensitive tags.

>
> Thanks,
>
> Mike

Craig


--
====================
See you at ApacheCon Europe <http://www.apachecon.com>!
Session VS01 (23-Oct 13h00-17h00):  Sun Technical Briefing
Session T06  (24-Oct 14h00-15h00):  Migrating Apache JServ
                                    Applications to Tomcat



Mime
View raw message