AbSoLution8
AbSoLution8

Reputation: 1213

struts2 nest text tag with property tag in jsp

I have been researching this online for a long while with no luck so I decide to ask.

In my application, the action class generates a value, which I can display through the

s:property
tag without a problem. However, since that string also has to be translated to other languages, I want to use that property value as the key for the

s:text
tag.

Obviously,

<s:text name="<s:property value="variable"/>"/>

doesn't work.

How can I do this without first translating it in the action class? I can do this within the java action class, but I want this to be done in the jsp because I want to preserve the variable. It has some signifance in some other javascript function.

Upvotes: 1

Views: 1828

Answers (1)

Jaiwo99
Jaiwo99

Reputation: 10017

it is very easy. If your action class extends ActionSupport, you can always do this in your jsp file.

<s:property value="getText('your.key')"/>

your.key should be saved in your struts2 language.properties file

EDIT

If you are using a dynamic string, you should replace your.key with an action property.

<s:property value="getText(yourProperty)"/>

Upvotes: 4

Related Questions