Tiles2 Struts Switch Locale
I am newbee to struts2 and tiles2, I am having an application where i m using struts2 as mvc framework and tiles2 as a view component. In my application I am using 2 languages English and Marathi the respective locales are en_US and mr_IN I have tiles.xml and tiles_mr_IN.xml when i switch locale from browser the code works fine but i want to toggle between English and Marathi and the user should be redirected to same action with same request parameters. I have tried satting request_locale parameter but it didnt开发者_Python百科 work. I could find that if i could switch locale in the request header or pass locale from struts2 to tiles lisner or some thing like that please help
This issue should be resolvable with a couple s2 jsp tags.
This link shows part of what you need: http://struts.apache.org/2.0.14/docs/how-do-we-change-locales.html
That is it shows how to take a s2 url add a parameter and then use that to set the locale.
If there is a parameter called "request_locale" coming in the i18n interceptor will use that over the user agents language preference.
To make the example better suited for a template change
<s:url id="en" action="Welcome">
to
<s:url includeParams="get">
Notice the action name has been omitted, this will default to the current action (which is ideal for your template) next the includeParams="get" will add all the parameters back into the url so they'll be passed into the action when you use the anchor. The includeParams may be "none", "get" or "all" (doing what you would expect). For more information on the s2 url tag see: http://struts.apache.org/2.2.1.1/docs/url.html
Further note that the s2 a tag shares most of the same funcationality as the s2 url tag taking advantage of this will produce:
<s:a includeParams="get">
<s:param name="request_locale" value="en_US"/>
English
</s:a>
<s:a includeParams="get">
<s:param name="request_locale" value="mr_IN"/>
Marathi
</s:a>
精彩评论