• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Locale Switching in Struts2

 
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,
I am developing a web app using Struts 2 which should support multiple locales.

My requirement is the user will be given a dropdown list of all the supporting locales. When the user select a different locale i need to set that locale and redisplay the current page with the changed locale content.


Can anybody sugest me how to do this?
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
http://struts.apache.org/2.1.6/docs/i18n-interceptor.html

That's pretty much all you need to do if you're running with the default interceptor stack.
 
Siva Prasad Reddy Katamreddy
Ranch Hand
Posts: 32
Eclipse IDE Spring Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Thanks for your reply.

The documentation is fine. But in this case i ahvae to specify where to go after changing the locale with


<result name="success">good_result.ftl</result>

But in my scenario, i don't know from which page the user do change the locale since the locale options drop down will be in all the pages.

Then how can i know to which page it should be forwarded?
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can just return to the page you were on, I suppose. The I18N is handled by the interceptor--if the form tag contains no action it will do a post-back.
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

David Newton wrote:You can just return to the page you were on, I suppose. The I18N is handled by the interceptor--if the form tag contains no action it will do a post-back.




problem with post back is previous page/form values are not re-submitted so control goes to 1 page behind complaining to re-submit the values...here is my problem..

i have a very basic requirement to put a toggle link between english and spanish on top of tile (say header.jsp) and this toggle link to be available in all pages in application... So user can change language on any of the page.. My very basic question is that if i follow struts2 documentation, i need to call an action and specify request_locale=en with that action.. But with this approach i will be redirected from my current form/jsp to another one..
i have one common header.jsp which is available in all pages..my flow works that action is executed and on its success a page with tiles is rendered, now on this tiles page (in header.jsp) i want to change language, which means i need to find dynamically what is my current action and then re-send previous request or call this action again with "request_locale=es" as parameter.

- How do i find current or last action in header.jsp?
- how do i re-submit same action with different locale, if i invoke URI for already processed action, it might complain about where previous form values are as it need those again to come to current page? As a matter of fact i will be returned to previous page form.. Am i wrong here

Any sample code, how header.jsp should look like for changing language in any page?if i have to invoke a new action alltogether, how will i come back to my current page. How does i18 work
 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What you did to resolve locale switching?
 
reply
    Bookmark Topic Watch Topic
  • New Topic