将 EL 2.2 与 Tomcat 6.0.24 结合使用
使用 JSF 2,您应该能够执行以下操作:
<h:commandButton action="#{myBean.myAction(myParameter)}"/>
然后调用操作方法,传入参数(假设它是一个整数):
@ManagedBean
@SessionScoped
public class MyBean {
...
public String myAction(Integer myParameter) {
// do something
return null;
}
...
}
这在 Glassfish v3 上完美运行。然而,在 Tomcat 上则不然,您会收到一个 ELException 通知解析错误
Caused by: javax.el.ELException: Error Parsing: ...
现在,有一个 记录的方法可以使用EL 2.2 和 Glassfish 的实现是通过替换 Tomcat lib 目录中的 el-api jar 来实现的,但是我仍然遇到同样的错误,但运气不佳。 Tomcat 真的开始让我感到沮丧了! JSF2 旨在变得更简单!
Maven POM 片段:
<repositories>
<repository>
<id>sun</id>
<url>http://download.java.net/maven/2/</url>
</repository>
<repository>
<id>jboss</id>
<url>http://repository.jboss.com/maven2/</url>
</repository>
</repositories>
...
<dependency>
<groupId>javax.el</groupId>
<artifactId>el-api</artifactId>
<version>2.2</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.glassfish.web</groupId>
<artifactId>el-impl</artifactId>
<version>2.2</version>
<scope>provided</scope>
</dependency>
更多信息。
这是堆栈跟踪的一部分,似乎它仍在使用 Apache EL 实现,而不是我转储到 lib 中的实现。我完全删除了 Tomcat 附带的现有 el-api.jar
,是否有一个 el-impl.jar
我也打算删除某个可能会覆盖某些内容的地方?
Was expecting one of:
"}" ...
"." ...
"[" ...
">" ...
"gt" ...
"<" ...
"lt" ...
">=" ...
"ge" ...
"<=" ...
"le" ...
"==" ...
"eq" ...
"!=" ...
"ne" ...
"&&" ...
"and" ...
"||" ...
"or" ...
"*" ...
"+" ...
"-" ...
"/" ...
"div" ...
"%" ...
"mod" ...
at org.apache.el.parser.ELParser.generateParseException(ELParser.java:2142)
at org.apache.el.parser.ELParser.jj_consume_token(ELParser.java:2024)
at org.apache.el.parser.ELParser.DeferredExpression(ELParser.java:113)
at org.apache.el.parser.ELParser.CompositeExpression(ELParser.java:40)
at org.apache.el.lang.ExpressionBuilder.createNodeInternal(ExpressionBuilder.java:93)
... 64 more
With JSF 2 you should be able to do this:
<h:commandButton action="#{myBean.myAction(myParameter)}"/>
which would then call the action method, passing in the parameter (assume it's an Integer):
@ManagedBean
@SessionScoped
public class MyBean {
...
public String myAction(Integer myParameter) {
// do something
return null;
}
...
}
This works on Glassfish v3 perfectly. However not on Tomcat, you get an ELException notifying of the parse error
Caused by: javax.el.ELException: Error Parsing: ...
Now, there's a documented way of making this work using EL 2.2 and Glassfish's implementation by replacing the el-api
jar in the Tomcat lib directory, however I still get the same error occurring with no luck. Tomcat's really starting to frustrate me! JSF2 is meant to be easier!
Maven POM fragments:
<repositories>
<repository>
<id>sun</id>
<url>http://download.java.net/maven/2/</url>
</repository>
<repository>
<id>jboss</id>
<url>http://repository.jboss.com/maven2/</url>
</repository>
</repositories>
...
<dependency>
<groupId>javax.el</groupId>
<artifactId>el-api</artifactId>
<version>2.2</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.glassfish.web</groupId>
<artifactId>el-impl</artifactId>
<version>2.2</version>
<scope>provided</scope>
</dependency>
More info.
Here's part of the stack trace, seems it's still using an Apache EL implementation, and not the one I dumped into lib. I completely removed the existing el-api.jar
that came with Tomcat, is there an el-impl.jar
I'm meant to remove somewhere too that may be overriding something?
Was expecting one of:
"}" ...
"." ...
"[" ...
">" ...
"gt" ...
"<" ...
"lt" ...
">=" ...
"ge" ...
"<=" ...
"le" ...
"==" ...
"eq" ...
"!=" ...
"ne" ...
"&&" ...
"and" ...
"||" ...
"or" ...
"*" ...
"+" ...
"-" ...
"/" ...
"div" ...
"%" ...
"mod" ...
at org.apache.el.parser.ELParser.generateParseException(ELParser.java:2142)
at org.apache.el.parser.ELParser.jj_consume_token(ELParser.java:2024)
at org.apache.el.parser.ELParser.DeferredExpression(ELParser.java:113)
at org.apache.el.parser.ELParser.CompositeExpression(ELParser.java:40)
at org.apache.el.lang.ExpressionBuilder.createNodeInternal(ExpressionBuilder.java:93)
... 64 more
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
正如其他答案中提到的,您需要将 el-api-2.2.jar 添加到 Tomcat 服务器的 lib 文件夹,并将 el-impl-2.2.jar 添加到 WEB-INF/lib 文件夹。
其他答案提到删除 jasper 或创建 ExpressionFactoryImpl 的自定义实现。这可能有效,但您不需要这样做。
您只需要在 MyFaces 上使用 org.apache.myfaces.EXPRESSION_FACTORY 或在 Mojarra 上使用 com.sun.faces.expressionFactory 覆盖表达式工厂实现。
As mentioned in other answers, you need to add the el-api-2.2.jar to your Tomcat server's lib folder, and the el-impl-2.2.jar to your WEB-INF/lib folder.
Other answers mention deleting jasper or creating custom implementations of ExpressionFactoryImpl. That might work, but you shouldn't need to do that.
You just need to override the expression factory implementation using org.apache.myfaces.EXPRESSION_FACTORY on MyFaces or com.sun.faces.expressionFactory on Mojarra.
正如我在评论中提到的,这可以通过升级 EL 实现来解决(即用 el-impl-2.2.jar 替换 jasper-el.jar)
As I mentioned in a comment, this can be solved by upgrading the EL implementation (i.e. replacing jasper-el.jar with el-impl-2.2.jar)
您可以使用 JBoss EL。
它是表达式语言 2.1 的实现。但它具有允许方法参数的扩展,如您的示例所示:
优点是您只需更改您的 web 应用程序,而不需要更改 Tomcat 的 lib 目录。
说明
lib /jboss-el.jar
WEB-INF/lib/jboss-el.jar
在您的
web.xml
集中:另请参阅调用直接方法或带 EL 中参数的方法。
You can use JBoss EL.
It's an implementation of Expression Language 2.1. But it has extensions to allow method parameters as in your example:
The advantage is that you only have to change your webapp and not Tomcat's lib directory.
Instructions
lib/jboss-el.jar
WEB-INF/lib/jboss-el.jar
In your
web.xml
set:See also Invoke direct methods or methods with parameters in EL.
将 el-api.jar 和 el-impl.jar 替换为 el-api-2.2.jar 和 el-impl-2.2.jar 可以解决该问题。
您还需要在 context.xml 中添加 context 参数
Replacing el-api.jar and el-impl.jar with el-api-2.2.jar and el-impl-2.2.jar solve the problem.
Also you need to add in your context.xml the context parameter