Hi everyone,

I have the following problem and cannot find a real solution to it. Usually 
this should be a common and known problem, so I'm wondering if I anyone has 
found a solution to this.

I have internationalized my struts 1.2.7 application through tiles and the use 
of ResourceBundle an java.util.Local.
Now I want to add a few buttons (one for every language) with which I can 
change the language on every page (as seen in many international webseites).
My first idea was to create an action that changes the locale and redirects 
back to page. My action-class looks like this:


public class SwitchLanguageAction extends Action{
                
    public ActionForward execute(ActionMapping mapping, ActionForm form, 
HttpServletRequest request, HttpServletResponse response)  
        throws IOException, ServletException {
        
        ActionForward forward = null;
        
        String lang = 
request.getParameter("lang"); //System.out.println("lang:" + lang);
        
        if( lang == null )
            return (mapping.findForward("failed"));

        setLocale( request, new Locale(lang.toUpperCase()) );
        
        String referer = 
request.getHeader("referer"); //System.out.println("referer:" + referer);
        
        forward = new RedirectingActionForward(referer);       
        
        return forward;
    }
    
}

In my JSP-Page I call this action-class like this:

<html:link href="/switchLanguage.do?lang=de"><html:img 
srcKey="icons.flags.german" bundle="mediaResources" border="0" /></html:link>
                        <html:link href="/switchLanguage.do?lang=en"><html:img 
srcKey="icons.flags.english" bundle="mediaResources" 
border="0" /></html:link>
                        <html:link href="/switchLanguage.do?lang=nl"><html:img 
srcKey="icons.flags.netherland" bundle="mediaResources" 
border="0" /></html:link>

The change of the locale works perfectly and the new values are displayed on 
the page. The only problem I have right know is, that if my "referer" was a 
".do"-page, the execute-method of my action-class is called and executed 
again (see my other posting). So this cannot be the solution. If I manually 
remove the .do in my referer-string, the action-class isn't called anymore 
but the refering page is wrong. 

Does anyone has a solution on how to change the language dynamically and can 
send me his solution or can help me with my current solution? At least this 
problem probably occurs on many, many pages that have mulit-language support. 
So I guess there should be a good solution to it? But I couldn't find any on 
the web.

Thank you very much in advance

Thomas
                        

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to