Sean Giles wrote:
Thanks Craig I'm using Jrun 3.0 and downloaded the service pak and the session.setAtttribute(Action.Locale_key,<locale> now seems to be working.

From a design standpoint what is the best way to set the locale information regardless of browser or machine settings to build the initial Accept-language header?  Another servlet that reads a cookie and builds the headers before directing the request to the struts action servlet?
 

A persistent cookie is the only way I can think of to know the user's preference before they log on.

In a Servlet 2.3 environment, this would be a perfect task for a Filter, which could examine each request for a persistent cookie, and set the Locale based on that cookie's values if it was not there yet.  You could, of course, automatically log the user on as well.

 
Basically I have a requirement for a user to be able to switch between languages on the fly but also being able to set an initial locale preference when they log in.  The struts framework handles the switching without a problem (which is really cool) its the initial display that I'm wondering about since they may have us_english for a machine setting, browser setting for spanish and an initial application locale preference for French.
 
In the absence of being able to use Filters, the only thing I can think of would be to create your own specialized version of the <html:html> tag that looked for the persistent cookie and set the locale appropriate, if the cookie was there and the Locale was not set yet.  You'd also want to create your own custom subclass of ActionServlet, and override the processLocale() method to do the same thing, in case the initial request was sent to a "*.do" URI instead of to a JSP page.
 
Thanks again,
Sean
 
Craig

PS:  I'm going to segregate the locale setting code in HtmlTag into a separate method so that it is easier to subclass this class.
 
 

Reply via email to