Tiles Struts /EL Expressions

六眼飞鱼酱① 提交于 2019-12-08 07:33:10

问题


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?


回答1:


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 the getText 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.



来源:https://stackoverflow.com/questions/8061953/tiles-struts-el-expressions

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!