In Struts 1 the <bean:message> tag is usually used with the key attribute in order to get the message from the properties file by specifying the message-key in the key attribute.
And in struts 2 we do that by using either <s:text> or <s:property> tags.
Consider the below example:
In struts 1,
<bean:message key="user.name.required"/>
The equivalent in Struts 2 is,
<s:text name="user.name.required" /> or
<s:property value="getText('user.name.required')"/> where,
user.name.required = Name is required
is the content of the properties file.
But I'm confused with a different scenario.
<bean:message name="user" property="label" />
for this, I tried <s:property value="getText('label')"/>
but the value returned is the string "label" instead of the message string "User data is missing"
and I also tried <s:property value="label"/>
But the value returned is message key i.e. "user.data.missing" instead of the message string "User data is missing"
<bean:message name="user" property="label" /> in Struts 1 returns the message User data is missing.
where,
user.data.missing=User data is missing
is the content of the properties file.
My question is how do I achieve this in Struts 2?
CodePudding user response:
Try the following code
<s:property value="getText(label)"/>
where label is a variable in the value stack which contains a message key i.e. "user.data.missing" .
