tags:

views:

29

answers:

1

Hi,

I have a Struts 1 application using standard Struts internationalization, with a property file and everything. I need to change a specific message for only a select group of users, so I want to extend PropertyMessageResources. However, I can't find a way to connect the current request (so that I know whether it's one of those select users) to the message lookup.

1) Is there a better way to get this functionality? I thought about putting logic in the jsp's, but that doesn't get some situations, like messages obtained through the validator.

2) Is there a possible way to connect the request to the various getMessage() methods of my extended PropertyMessageResources object?

A: 

Here's what I ended up doing:

-In the login script, check if it's one of the select users, and add a special String to the Variant part of their Locale, and put it in the session as their locale.

request.getSession(true).setAttribute("org.apache.struts.action.LOCALE", new Locale(locale.getLanguage(), locale.getCountry(), customVariant);

-In the overridden PropertyMessageResources class, in the getMessage(Locale,String) method, just check the locale passed in to see if it has the special variant. I made all my custom variants start with a "_", and I check the first character of the variant before looking it up (so as to not slow down other users).

If anyone has a better solution, please post it.

NJCodeMonkey