Title: RE: ActionServlet to change language ?

One solution is for each page to have a hidden field that contains it's relative path.  Then you can forard to that page after you have changed the locale.

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
Sent: Monday, May 07, 2001 5:17 AM
To: [EMAIL PROTECTED]
Subject: ActionServlet to change language ?


Hi all,

I want to use a simple action to change the language in a site,
but I would like this feature to be available on all pages of the site.
I'm using a template, and the same menu (with language selection)
is included in each page.
My question is : When a visitor decide to change the language,
how could I know the URL where he was and where I had to come
back ?

In other words, how can I complete the following code ?

+++++++++++++++++++++++++++++++++++++++++++++
public final class ChangeLang extends Action {

    public ActionForward perform(
                            ActionMapping mapping,
                            ActionForm form,
                            HttpServletRequest request,
                            HttpServletResponse response)
       throws IOException, ServletException {

       // Extract parameters we will need
    String requested = (String)request.getParameter( "lang" );

    if( requested == null )
           return (mapping.findForward("error"));
    if( requested.equalsIgnoreCase( "FR" ) )
      setLocale( request, Locale.FRANCE );
    if( requested.equalsIgnoreCase( "UK" ) )
      setLocale( request, Locale.UK );
    if( requested.equalsIgnoreCase( "DE" ) )
      setLocale( request, Locale.GERMAN );

    return ( ????? );
    }

    protected void setLocale( HttpServletRequest request, Locale locale
)
      {
      HttpSession session = request.getSession(false);
      if (session != null)
        session.setAttribute(Action.LOCALE_KEY, locale);
      }
}
+++++++++++++++++++++++++++++++++++++++++++++


In my strus-config.xml :

+++++++++++++++++++++++++++++++++++++++++++++
  <action-mappings>
    <action path="/ChLang"  actionClass="classes.ChangeLang">
      <forward name="error" path="/error.jsp"/>
    </action>
  </action-mappings>
+++++++++++++++++++++++++++++++++++++++++++++

My menu :

+++++++++++++++++++++++++++++++++++++++++++++
<%@ taglib uri='/WEB-INF/struts-html.tld' prefix='html' %>
<table width="100%">
<tr>
 <td>
Select Language :
<html:link page="/ChLang.do?lang=FR">FR</html:link> |
<html:link page="/ChLang.do?lang=EN">EN</html:link> |
<html:link page="/ChLang.do?lang=NL">NL</html:link> |
<html:link page="/ChLang.do?lang=D">D</html:link>
 </td>
</tr>
</table>
+++++++++++++++++++++++++++++++++++++++++++++

Thanks.
--
Olivier DUCHÊNE

Reply via email to