Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

struts locale

 
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Niklas Rosencrantz
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It seems to work in action class with messageResources.getMessage("congratulations") instead. Now how in jsp?
Thank you
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
    Bookmark Topic Watch Topic
  • New Topic