Apache Struts 2 Documentation > Home > FAQs > How do I add I18N to a UI tag, like the textfield tag
Added by digi9ten, last edited by Ted Husted on Jul 22, 2006  (view change) show comment

The simplest way to inject resource bundle messages into tag attributes is to use the Action's getText method. Another way is to edit the tag templates to use the resource bundle by default.

Calling getText

<saf:textfield label="%{getText('label.firstName')}" name="firstName" />

The getText method will look for an entry in the resource bundle with the key "label.firstName", and the value of the "firstName" property will be provided by the Action, or some other object on the Value Stack.

Ediing the Templates

If using the resource bundle is the default for your application, you might consider modifying the controlheader-core.ftl template. If the xhtml theme is being used, the original template is found at {{/template/xhtml}.

controlheader-core.ftl
${parameters.label?html}:<#t/>
<#assign mm="getText('"+parameters.label?html+"')" /><#t/>
${stack.findValue(mm)}:<#t/>

or

${stack.findValue("getText('"+parameters.label?html+"')")}

After making the change, tags with a label attribute will use the value you set as a key.

<saf:textfield label="label.firstName" name="firstName" />