wood burning stoves 2.0*
The moose likes Struts and the fly likes struts locale Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "struts locale" Watch "struts locale" New topic
Author

struts locale

Niklas Rosencrantz
Ranch Hand

Joined: Apr 08, 2006
Posts: 49
How would you change the locale in an Action class? I try setLocale( request, new Locale("pt","BR") ); but it doesn't seem too do it.
Thank you
Niklas R
Quince bise
Greenhorn

Joined: Jan 22, 2008
Posts: 8
Hi,
i have tried this on my application. i used java.util.Locale

//get locale default
Locale locale = Locale.getDefault();
//set custom locale
locale = new Locale("es", ES");
Locale.setDefault(locale);

i hope this will work...
Niklas Rosencrantz
Ranch Hand

Joined: Apr 08, 2006
Posts: 49
Thank you. I try in my jsp

But it gets displayed with messageresources from the browser's locale. Is there something I forget?
Thanks
Niklas R
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
You had the right idea with your first post. Add one more thing, and it should work. In your struts-config.xml file, add the following:

This will tell Struts not to put the browser locale in the session, but to let you do it manually.


Merrill
Consultant, Sima Solutions
Niklas Rosencrantz
Ranch Hand

Joined: Apr 08, 2006
Posts: 49
Thanks for the great suggestions. Here's the action I'm trying to internationalize and localize:

I also need overriding the browser's locale directly in a JSP page using struts messageresources, it it possible in the same manner?
Thank you
Niklas R
Niklas Rosencrantz
Ranch Hand

Joined: Apr 08, 2006
Posts: 49
It seems to work in action class with messageResources.getMessage("congratulations") instead. Now how in jsp?
Thank you
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
Are you using the Stuts <bean:message /> tags? If not, that's why it doesn't work. Only the Struts tags are affected by this code, not JSTL tags.
Niklas Rosencrantz
Ranch Hand

Joined: Apr 08, 2006
Posts: 49
Yes, I do use bean:message. It seems to work fine in action class but how to do it in JSP in beyond me at this moment.
[ April 03, 2008: Message edited by: Niklas Rosencrantz ]
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
Make sure that you never reference a JSP directly. For example, the user should never enter a URL like MyServer/MyApp/Mypage.jsp. The URLs entered or clicked by the user should always point to an action that in turn forwards to a JSP. Example: MyServer/MyApp/MyAction.do

Then just make sure you set the locale in the action that forwards to the JSP.
[ April 03, 2008: Message edited by: Merrill Higginson ]
Niklas Rosencrantz
Ranch Hand

Joined: Apr 08, 2006
Posts: 49
Thank you so much for the clear instructions. Now I understand how to do it and have no further questions.
Best regards,
Niklas
Niklas Rosencrantz
Ranch Hand

Joined: Apr 08, 2006
Posts: 49
How come the following outputs are not the same:

The two log messages are in different languages. There is something I've misunderstood since I expect the output from the two log messages to be identical. Could somebody please explain?
Thank you
Niklas
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: struts locale
 
Similar Threads
how to get client country name?
UK Locale problem
Locale Switching in Struts2
"LocaleBug"
bean:write property