问题
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??
回答1:
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}"/>
来源:https://stackoverflow.com/questions/13920587/struts2-messageresources-in-apache-tiles