Struts2 MessageResources in Apache Tiles

I am trying unsuccessfully to use the Struts2 message resource in tile 2.1.4. For example, the following resource is available in JSP ...

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

... but when I try to use the same resource in the tile definition ...

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

... I get an error...

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

... Is there a way to do this?

+1
struts2 tiles2
source share
1 answer

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

In the tile definition:

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

In your JSP, use the Struts2 <s:set> to set the title from the fragment definition to a local variable, and then use it in the <s:text> .

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

All Articles