Struts2 MessageResources in Apache Tiles

2020-04-20 15:48发布

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条回答
淡お忘
2楼-- · 2020-04-20 16:27

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}"/>
查看更多
登录 后发表回答