Search code examples
struts2ognl

messages bundle with dynamic key in struts2


I have a problem with displaying a message from messages bundle with key passed as a tag argument. Since version 2.3, struts tags don't allow runtime expressions.

I have a custom tag with fieldName parameter and I want to retrieve a message with use of this parameter, like in previous versions of the framework: <s:text name="${fieldName}"/>

Neither <s:text> nor <s:property> work for me.

I tried every solution found in web, but nothing works.


Solution

  • Use OGNL or use <s:set> tag

    <s:set name="fname">
      ${fieldName}
    </s:set>
    
    <s:text name="%{#fname}"/>