You just have to put a Locale object in session scope :

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

Struts will use associated messagesRessources.

Nico.



This might be a tricky way, but our users should select the language at
startup.

Our login.jsp has this part:
<tr><td><bean:message key="login.username" /></td></tr>
  <tr><td><html:text property="username" value=""/></td></tr>
  <tr><td><bean:message key="login.password" /></td></tr>
  <tr><td><html:password property="password" value=""/></td></tr>
  <br>
  <tr><td><bean:message key="login.language" /></td></tr>
  <tr><td>
            <html:select property="language" size="1" value="">
            <html:option value="DE">DE</html:option>
            <html:option value="EN">EN</html:option>
        </html:select>
  </td></tr>

The User selects his language option and the value is saved in the
loginForm-Bean when the user submits.
Now I need a trigger whick checks up the value of the variable "language"
in the loginForm-Bean.
This might be a part of code in the LoginAction-Class.
Testing the value of the variable "language" might be easy, but how can I
set the locale-Attribut in the Session?
If the user selects maybe "EN" the right Resource-File (
ApplicationResources_en.properties) must be load.
Has anybody an idea which code I need in the LogonAction-Class?

Manuel Lenz


e-mail: [EMAIL PROTECTED]
web: www.viessmann.com


|---------+--------------------------->
|         |                           |
|         |                           |
|         |                           |
|         |[EMAIL PROTECTED]|
|         |26.03.2003 09:39           |
|         |Bitte antworten an "Struts |
|         |Users Mailing List"        |
|         |                           |
|---------+--------------------------->

>-----------------------------------------------------------------------------------------------------------------------
------|
  |
|
  |     An:       [EMAIL PROTECTED]
|
  |     Kopie:
|
  |     Thema:    RE: Pull-down-menue for "language select" at logon
|

>-----------------------------------------------------------------------------------------------------------------------
------|




it could be something like this, but it depends mostly on your back end
system...


public final class ChangeLanguageAction extends Action {

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

    Locale locale = getLocale(request);
    MessageResources resource = getResources();
    ActionErrors errors = new ActionErrors();
    ModelBeans beans = new ModelBeans();

    String method = "perform";
    String className = this.getClass().getName();
    String activity = resource.getMessage("activity.action." +
className.substring(className.lastIndexOf(".") + 1));
    Log log = LogFactory.getLog(className);

    if (beans.isNew(request)) return mapping.findForward("home");

    // Get unsuccess action forward
    String input = ((LocaleForm) form).getInput();
    log.debug(method + ":input = " + input);
    ActionForward forward = new ActionForward((input !=
null?input:mapping.getInput()));

    log.info(method + ":begin");

    String language = ((LocaleForm) form).getLanguage();
    log.debug(method + ":language = " + language);

    ProfileBean profileBean = (ProfileBean)
beans.getBean(BEANFACTORY.PROFILE_KEY, request);

    setLocale(request,new Locale(language, ""));

    if (language.compareTo(Locale.ITALIAN.getLanguage()) == 0)
      profileBean.setLanguageId(APP._IT);
    else if (language.compareTo(Locale.ENGLISH.getLanguage()) == 0)
      profileBean.setLanguageId(APP._EN);
    else if (language.compareTo(Locale.GERMAN.getLanguage()) == 0)
      profileBean.setLanguageId(APP._DE);
    else if (language.compareTo(Locale.FRENCH.getLanguage()) == 0)
      profileBean.setLanguageId(APP._FR);
    else if (language.compareTo("es") == 0)
      profileBean.setLanguageId(APP._ES);
    else
      profileBean.setLanguageId(APP._EN);

    if (!errors.empty())
      saveErrors(request, errors);

    log.debug(method + ":forward to " + forward.getPath());
    log.info(method + ":end");

    return forward;
  }

}



> -----Original Message-----
> From:            [EMAIL PROTECTED] [SMTP:[EMAIL PROTECTED]
> Sent:            Wednesday, March 26, 2003 9:31 AM
> To:        [EMAIL PROTECTED]
> Subject:         RE: Pull-down-menue for "language select" at logon
>
> Do you have an example of "changelanguage.do"?
>
>
>   _____
>
> Thank You
>
> Mick Knutson
>
> Sr. Designer - Project Trust
> aUBS AG, Financial - Zürich
> Office: +41 (0)1/234.42.75
> Internal: 48194
> Mobile: 079.726.14.26
>   _____
>
>
>
> -----Original Message-----
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
> Sent: Wednesday, March 26, 2003 9:18 AM
> To: [EMAIL PROTECTED]
> Subject: RE: Pull-down-menue for "language select" at logon
>
>
> Why not using a toolbar with icons so users can change the language
> whenever
> they want?
> something like:
>
> <SCRIPT LANGUAGE="JAVASCRIPT">
>
>
>   function changeLanguage(language) {
>
> document.location='<%=request.getContextPath()%>/changelanguage.do?input
=<
> %=
> request.getServletPath()%>&language=' + language;
>   }
>
> </SCRIPT>
>
> <TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH="100%"
> background='<bean:write name="img"/>/icon.logo.jpg'>
> <TR id="OLD"  style="display: ;">
>     <TD height='35' WIDTH="200">&nbsp;</TD>
>     <TD width = 128 VALIGN="MIDDLE" ALIGN='left;'></TD>
>     <TD WIDTH = 250  VALIGN='BOTTOM' ALIGN='CENTER'>&nbsp;</TD>
>     <TD width="150" ID="lang" align = "right"
> valign=middle>&nbsp;&nbsp;&nbsp;
>         <IMG ID="icon" SRC='<bean:write name="img"/>/gb.jpg'
> ONCLICK='changeLanguage("en");' TITLE='<bean:message
> key="language.english"/>'>&nbsp;
>         <IMG ID="icon" SRC='<bean:write name="img"/>/de.jpg'
> ONCLICK='changeLanguage("de");' TITLE='<bean:message
> key="language.german"/>'>&nbsp;
>         <IMG ID="icon" SRC='<bean:write name="img"/>/fr.jpg'
> ONCLICK='changeLanguage("fr");' TITLE='<bean:message
> key="language.french"/>'>&nbsp;
>         <IMG ID="icon" SRC='<bean:write name="img"/>/it.jpg'
> ONCLICK='changeLanguage("it");' TITLE='<bean:message
> key="language.italian"/>'>&nbsp;
>     </TD>
> </TR>
>  <TR id="OLD" style="display: ;">
>             <TD WIDTH="50" colspan="5">&nbsp;</TD>
>  </TR>
> </TABLE>
>
> <SCRIPT LANGUAGE='javascript'>
>     for (var i=0; i < document.all["icon"].length ;i++)
>         document.all["icon"][i].style.cursor = 'hand';
>     document.all["ntext"].focus();
> </SCRIPT>
>
> > -----Original Message-----
> > From:          Manuel Lenz [SMTP:[EMAIL PROTECTED]
> > Sent:          Wednesday, March 26, 2003 9:10 AM
> > To:            [EMAIL PROTECTED]
> > Subject:             Pull-down-menue for "language select" at logon
> >
> >
> > Hi Struts-Community,
> > I´m developing a smart workflow for ordering materials in our company.
> > This web-application will be used in several countries, so we have to
> > implement several languages.
> > The most users may not have a browser using their language.
> > I´d like to desing a "pull-down"-menue where every user can select his
> > language at logon.
> > Can anybody help me doing this?
> > At the moment i have created some .properties-files and .jsp-files
using
> > them.
> >
> > Greetings,
> > Manuel Lenz
> >
> > e-mail: [EMAIL PROTECTED]
> > web: www.viessmann.com
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> >
> >
> IMPORTANT:
> This e-mail transmission is intended for the named addressee(s) only.
> Its contents are private, confidential and protected from disclosure and
> should not be read, copied or disclosed by any other person.
> If you are not the intended recipient, we kindly ask you to notify the
> sender immediately by telephone (+41-91-612 26 11),
> to redirect the message to the account "[EMAIL PROTECTED]" and to delete
> this
> e-mail.
> E-mail transmissions may be intercepted, altered or read by unauthorized
> persons and may contain viruses. Therefore, it is recommended that you
use
> regular mail or courier services for any information intended to be
> confidential. However, by sending us messages through e-mail, you
> authorize
> and instruct us to correspond by e-mail in the relevant matter.
> Thank you.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
> Visit our website at http://www.ubswarburg.com
>
> This message contains confidential information and is intended only
> for the individual named.  If you are not the named addressee you
> should not disseminate, distribute or copy this e-mail.  Please
> notify the sender immediately by e-mail if you have received this
> e-mail by mistake and delete this e-mail from your system.
>
> E-mail transmission cannot be guaranteed to be secure or error-free
> as information could be intercepted, corrupted, lost, destroyed,
> arrive late or incomplete, or contain viruses.  The sender therefore
> does not accept liability for any errors or omissions in the contents
> of this message which arise as a result of e-mail transmission.  If
> verification is required please request a hard-copy version.  This
> message is provided for informational purposes and should not be
> construed as a solicitation or offer to buy or sell any securities or
> related financial instruments.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
IMPORTANT:
This e-mail transmission is intended for the named addressee(s) only.
Its contents are private, confidential and protected from disclosure and
should not be read, copied or disclosed by any other person.
If you are not the intended recipient, we kindly ask you to notify the
sender immediately by telephone (+41-91-612 26 11),
to redirect the message to the account "[EMAIL PROTECTED]" and to delete this
e-mail.
E-mail transmissions may be intercepted, altered or read by unauthorized
persons and may contain viruses. Therefore, it is recommended that you use
regular mail or courier services for any information intended to be
confidential. However, by sending us messages through e-mail, you authorize
and instruct us to correspond by e-mail in the relevant matter.
Thank you.


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







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


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

Reply via email to