Tiles Struts /EL 表达式
我正在使用 Struts 2.2.3 和 Tiles 2.1.4。它工作得很好,但现在我尝试使用 EL 表达式,但无法让它工作。在 Struts2 中,我可以使用
并从包中检索消息。我想在瓷砖定义上使用相同的方法。到目前为止,我已将上下文参数添加到 web.xml
<context-param>
<param-name>org.apache.tiles.evaluator.AttributeEvaluator</param-name>
<param-value>org.apache.tiles.evaluator.el.ELAttributeEvaluator</param-value>
</context-param>
现在我想在定义上使用以下表达式:
<put-attribute name="pane-title"
expression="${getText('Dashboard.label')}"
cascade="true"/>
问题是,当我这样做时,无法创建屏幕,并显示:
Function ':getText' not发现
所以我想我错过了一些东西,但我不知道为什么。有什么想法吗?
I’m using Struts 2.2.3 with Tiles 2.1.4. It works absolutely fine, but now I’m trying to use EL expressions, and I can’t get it to work. In Struts2 I can use <s:property value="${getText('Dashboard.label')}"/>
and it retrieves the message from a bundle. I’d like to use the same on the Tiles Definition. So far I’ve added the context-param to the web.xml
<context-param>
<param-name>org.apache.tiles.evaluator.AttributeEvaluator</param-name>
<param-value>org.apache.tiles.evaluator.el.ELAttributeEvaluator</param-value>
</context-param>
Now I want to use the following expression on the definition:
<put-attribute name="pane-title"
expression="${getText('Dashboard.label')}"
cascade="true"/>
The issue is that when I do this, the screen fails to be created saying:
Function ':getText' not found
So I suppose I’m missing something, but I don’t know why. Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不相信这会起作用;您正在尝试将 OGNL 表达式计算为普通的旧 JSP EL。我看到了一些潜在的解决方案。
我会首先尝试最简单的方法(尽管从长远来看它可能不适合您的需求):使用
getDashboardLabel
函数(或其他函数)公开操作中的值,该函数使getText调用。这应该允许简单的属性查询
${dashboardLabel}
。这取决于 Tiles 解析 EL 与当前请求解析 EL 的方式:S2 使用瘦包装器将值堆栈公开给 JSP EL。
如果这不起作用或不适合您的需求,我认为下一个方法是看看您是否可以创建一个访问值堆栈的 Tiles 属性评估器并替换 org.apache.tiles.evaluator。 el.ELAttributeEvaluator。我不确定这有多容易/有多困难,我必须检查一下。如果您可以像现有 Struts 标签一样评估 OGNL,那可能会非常有趣。
哦,您也许也可以创建一个 JSP 函数库;不过,我不太确定 EL 评估器如何使用它;使用 JSP 就很容易了。
I don't believe that will work; you're trying to evaluate an OGNL expression as plain old JSP EL. I see a couple of potential solutions.
I'd try the easiest first (although it may not suit your needs in the long run): expose the value in the action, with a
getDashboardLabel
function (or whatever) that makes thegetText
call. This should allow a simple property query${dashboardLabel}
.This depends on Tiles resolving EL against how the current request resolves EL: S2 uses a thin wrapper to expose the value stack to JSP EL.
If that doesn't work or doesn't suit your needs, I think the next approach would be to see if you could create a Tiles attribute evaluator that accesses the value stack and replace the
org.apache.tiles.evaluator.el.ELAttributeEvaluator
. I'm not sure how easy/hard that would be, I'd have to check. If you can get that to evaluate OGNL the same way the existing Struts tags do, that could be pretty interesting.Oh, you might just be able to create a JSP function library, too; I'm not really sure how that would work with the EL evaluator, though; with JSP it's pretty easy.