Search code examples
javajspstruts2resourcebundleognl

Struts 2 text tag weird behavior


I am using the Struts2 text tag, to get a translated value. So, I have the following statement:

<s:text name="a"/>

I don't have any key 'a' in the properties files, but in the action, I have an object with name a.

What happens is that the value rendered by the s:text is the class name of the object instance (package.a@xyz)!

Is this normal? For what I know about Struts2, if no property with that key is found, the rendered value will be the key (text tag name attribute). Did this ever happened to anyone?


Solution

  • I think this is normal, because Struts2 parses attributes for OGNL expression, and the result of the expression evaluation will be used as a message key. However the doc says that searchValueStack should be used to prevent searches in the value stack. Which one is better decide to you, but I prefer <s:property value="getText('a')"/> as an alternative.