velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Markus Reinhardt <>
Subject MessageTool, change locale
Date Mon, 26 Jun 2006 07:36:32 GMT

I am using the struts-utils MessageTool in combination with struts and
am experiencing certain problems.

I have an action to switch the locale to a specified value which
executes the following code:

session.setAttribute(Globals.LOCALE_KEY, locale);

Where locale is choosen via HTTP request. This action works as intended
which means after execution
$request.session.getAttribute('org.apache.struts.action.LOCALE') returns
the correct locale (en or de in my case) and the page is displayed in
the chosen language.

But in some cases, I guess it happens if someone with default locale
'en' accesses my website everything gets mixed up.

Where the above action still works as mentioned above, the whole page
stays german for EVERY request (even with different session) until I
restart it via the tomcat manager.

I took a look in
getLocale(..) method:

public static Locale getLocale(HttpServletRequest request, HttpSession session)
  Locale locale = null;
  if (session != null)
    locale = (Locale)session.getAttribute(Globals.LOCALE_KEY);
  if (locale == null)
    locale = request.getLocale();
  return locale;

The MessageTool resides in request scope, which means this method should
return the session key. At least after my action was executed and a new
session created:

HttpSession session = request.getSession();

I really don't see the point where I did something wrong. Btw.
request.getLocale() always returns 'de' (even if the problem doesn't
appear). This at least explains why everything is german after the

Any help would be greatly appreciated,


View raw message