You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by bj...@accenture.com on 2007/04/24 08:48:03 UTC

Set language in JSP

I've encountered a rather annoying issue.  To select the language in which our labels should be displayed, we use fmt:setLocale.  Everything works fine, everybody's happy.

But.  To validate our forms, we use DynaValidator.  In our webapp, we have 1 form which has only 1 field.  When validation fails, the browser redisplays the form, with an appropriate error message.  The problem is that we show our error message with <html:errors /> and since struts doesn't know the locale which was set with fmt:setLocale, this message is retrieved from the resource bundle of the standard browser language.  

Is there anyone who knows how to set the language in a JSP, for that particular page?  It has to be on the page itself, it can't be done in an action or somewhere else.  Or maybe another way to show the error message with logic:messagesPresent and retrieval of the error message from a resource bundle.

Thanks in advance

Kind regards,
Bjorn De Bakker



This message is for the designated recipient only and may contain privileged, proprietary, or otherwise private information.  If you have received it in error, please notify the sender immediately and delete the original.  Any other use of the email by you is prohibited.

Re: Set language in JSP

Posted by Niall Pemberton <ni...@gmail.com>.
On 4/24/07, bjorn.de.bakker@accenture.com <bj...@accenture.com> wrote:
> I've encountered a rather annoying issue.  To select the language in which our labels should be displayed, we use fmt:setLocale.  Everything works fine, everybody's happy.
>
> But.  To validate our forms, we use DynaValidator.  In our webapp, we have 1 form which has only 1 field.  When validation fails, the browser redisplays the form, with an appropriate error message.  The problem is that we show our error message with <html:errors /> and since struts doesn't know the locale which was set with fmt:setLocale, this message is retrieved from the resource bundle of the standard browser language.

Struts uses either the Locale stored under a key in the Session
(default key is Globals.LOCALE_KEY, but you can specify an alternate
on tags like <html:errors/>) or if thats not present the default
locale for the request. So I think you have a number of options:

1) Set the locale in the Session
2) Create a custom TagUtils instance overriding the getUserLocale()
method (Struts 1.3.5 or later since thats when the static
setInstance() method was added to TagUtils).
3) Create your own custom equivalent of the <html:errors/> (or
<html:messages>) tag that access the ActionErrors object created by
the validation process

Niall

> Is there anyone who knows how to set the language in a JSP, for that particular page?  It has to be on the page itself, it can't be done in an action or somewhere else.  Or maybe another way to show the error message with logic:messagesPresent and retrieval of the error message from a resource bundle.
>
> Thanks in advance
>
> Kind regards,
> Bjorn De Bakker

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org