Link to home
Start Free TrialLog in
Avatar of heppa
heppaFlag for Luxembourg

asked on

Struts: Overwriting locale in the request

We are using Struts 1.1 (i know, it's old, but it's a constraint) to build a web application. We also have application.properties for 3 languages. Due to political decisions I am supposed to "remove" multilanguage support quickly, meaning that the application won't react on the given locale. My problem is, that it always reacts on the locale given in the request on first access.

I tried to set a fix locale to the session, both with setLocale(java.util.Locale) method as well as setting it to the session directly in the Action Delegation class (we have a GenericAction with an abstract method executeTask that extends Action and all other Actions are extending GenericAction). Both didn't have an effect on first request.

It is really the only option NOT to include the application_de.properties in the war in order to fall back to english all the time, even if the browser locale is set to, say, de_DE?

I appreciate any help very much, as I just started to try to understand Struts. It normally works out quite well, but this does not make sense to me. I thought, the setLocale method would have this exact purpose. Thanks a lot in advance.

Alex
SOLUTION
Avatar of TimYates
TimYates
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of heppa

ASKER

Hi Tim,

that's what I am doing (well, not exactly, but it's the same):

session.setAttribute(Globals.LOCALE_KEY,new Locale("en"));

the thing is, that in session the value is correct, but i have a Locale as defaultLocale as a request attribute, and it seems as if this one is used.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
>>Locale locale = Locale.getDefault();
Avatar of heppa

ASKER

Thanks a lot karanw,

I tried to set this both during application init and in the GenericAction, when I look at the request attribute that holds the PropertyMessageResources, it's default locale is english, and also the messages itself are the english ones, but still it is the properties file for the tomcat default Locale that is used in display. I think, I have a general understanding problem here. When Struts is reading in the PropertyMessageResources, does it read in all available ones and decide during runtime which element to retrieve? this would mean, that even when I set the locale inside the jsp it should work correctly.

My solution now is to set Tomcat's default locale to english, but this should normally not be necessary. One should be able to set the locale for a single WebApp. But how? I'm a bit lost here!

rgds. alex
Avatar of heppa

ASKER

Arghs, call me stupid.

following problem: when we give a certain parameter, the whole session will be invalidated. This is done during request processing. This also means that the set locale was not available in the session after processing...

thanks for your help!!! I will split points, as you were both right, and i appreciated your knowledge!
rgds. alex
:)