aspose file tools*
The moose likes Struts and the fly likes Locale Switching in Struts2 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Locale Switching in Struts2" Watch "Locale Switching in Struts2" New topic
Author

Locale Switching in Struts2

Siva Prasad Reddy Katamreddy
Ranch Hand

Joined: Jun 06, 2007
Posts: 32

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?
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

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

Joined: Jun 06, 2007
Posts: 32

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
Rancher

Joined: Sep 29, 2008
Posts: 12617

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.
k pruthi
Greenhorn

Joined: Aug 11, 2009
Posts: 3
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
Krishan Babbar
Greenhorn

Joined: Aug 30, 2010
Posts: 6
What you did to resolve locale switching?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Locale Switching in Struts2