struts2tiles2

Struts2 MessageResources in Apache Tiles


I'm trying unsuccessfully to use a Struts2 message resource in a tiles 2.1.4 expression. For example the following resource is available in the JSP...

<s:text name="htmlheadHeading1"/><br/>

... but when I attempt to use the same resource in the tiles definition...

<put-attribute name="title" expression="${htmlheadHeading1}" />

... I get the error...

ELResolver cannot handle a null base Object with identifier 'htmlheadHeading1'

... Is there any way to do this??


Solution

  • This solution does not use tiles expressions but will work if you need to display localized text in JSP when key is passed through tiles definitions.

    In tiles definition:

    <put-attribute name="title" value="htmlheadHeading1" />
    

    In your JSP then use Struts2 <s:set> tag to set title from tiles definition to local variable and then use it in <s:text> tag.

    <s:set var="title">
      <tiles:getAsString name="title" ignore="true"/>
    </s:set>
    <s:text name="%{#title}"/>