Search code examples
jspstruts2internationalizationstruts-tags

Get value from resource bundles using substitution in Struts 2


How can I get localized text in resource bundles using a substituted key?

I tried following code, but not work:

<s:i18n name="global">
  <s:text name="${top[0]}"></s:text>
</s:i18n>

I use <s:iterator value="#request.myArray"> where myArray is an ArrayList of pairs of strings and each element of the array represents the key from resource bundle.

ex: [{"a","1"},{"b","2"},{"c","3"}]

    <s:iterator value="#request.myArray">
    <tr>
        <td>
            <s:i18n name="global">
                <s:text name="${top[0]}"></s:text>
            </s:i18n>
            <s:property />
        </td>
      </tr>

</s:iterator>

and ${top[0]} is a,b,c etc.


Solution

  • You can't use EL inside Struts' tags attributes. But you can use OGNL.

    <s:text name="%{top[0]}"></s:text>