Tiles Struts/EL 表达式 [英] Tiles Struts /EL Expressions

查看:17
本文介绍了Tiles Struts/EL 表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 Struts 2.2.3 和 Tiles 2.1.4.它工作得很好,但现在我正在尝试使用 EL 表达式,但我无法让它工作.在 Struts2 中,我可以使用 <s:property value="${getText('Dashboard.label')}"/> 并从包中检索消息.我想在瓷砖定义上使用相同的.到目前为止,我已经将 context-param 添加到 web.xml

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:

找不到函数':getText'

Function ':getText' not found

所以我想我错过了一些东西,但我不知道为什么.有什么想法吗?

So I suppose I’m missing something, but I don’t know why. Any ideas?

推荐答案

我认为这行不通;您正在尝试将 OGNL 表达式评估为普通的旧 JSP EL.我看到了几个潜在的解决方案.

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.

我会先尝试最简单的(尽管从长远来看它可能不适合您的需求):公开操作中的值,使用 getDashboardLabel 函数(或其他函数)使 <代码>getText 调用.这应该允许一个简单的属性查询${dashboardLabel}.

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 the getText call. This should allow a simple property query ${dashboardLabel}.

这取决于 Tiles 根据当前请求如何解析 EL 来解析 EL:S2 使用瘦包装器将值堆栈公开给 JSP EL.

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.

如果这不起作用或不适合您的需求,我认为下一个方法是查看您是否可以创建一个 Tiles 属性评估器来访问值堆栈并替换 org.apache.tiles.evaluator.el.E​​LAttributeEvaluator.我不确定这有多容易/难,我必须检查一下.如果你能像现有的 Struts 标签一样使用它来评估 OGNL,那可能会非常有趣.

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.

哦,你也可以创建一个 JSP 函数库;不过,我不确定这将如何与 EL 评估器一起工作;使用 JSP 很容易.

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.

这篇关于Tiles Struts/EL 表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆