views:

2350

answers:

1

I need to use multiple resource files on my jsp to show localised messages. Whats the way to include it in struts 2.

I have seen <s:i18n name="">, but this will make the code pretty messy as it need to be written and closed for each of the labels.

I beleive there is message- resource tag in struts 1x which we can declare in struts config. But in struts 2 its not getting recognised.

Any thing similar on the lines to include it on the top of jsp and to use it later ?

Any idea ?

+1  A: 

In struts.properties, reference your resource files:

struts.locale=xx_XX
struts.custom.i18n.resources=global-errors, global-messages, ...

Make sure to put your resource files on the classpath and postfix the files with your locale (ie. global-errors_ xx _ XX.properties).

Then, in your JSP you can use the s:text-tag:

Example:

<s:text name="your.property"></s:text>

If you want to replace params in you property:

<s:text name="your.property">
<s:param name="value" value="%{something} />
</s:text>

If you need to use a different locale (translate your app), change the locale and add another resourece file postfixed with the new locale.

Agora