Apache Tiles中的Struts2 MessageResources [英] Struts2 MessageResources in Apache Tiles
问题描述
我尝试在磁贴中使用Struts2消息资源失败 2.1.4表达式.例如,以下资源可用于 JSP ...
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??
推荐答案
此解决方案不使用tile表达式,但是如果您需要在键通过tile定义传递键时在JSP中显示本地化文本,则可以使用该解决方案.
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.
在图块定义中:
<put-attribute name="title" value="htmlheadHeading1" />
然后在您的JSP中使用Struts2 <s:set>
标记将标题定义从图块定义设置为局部变量,然后在<s:text>
标记中使用它.
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}"/>
这篇关于Apache Tiles中的Struts2 MessageResources的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!