将 EL 2.2 与 Tomcat 6.0.24 结合使用

发布于 2024-08-22 17:48:11 字数 2505 浏览 9 评论 0原文

使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

迷路的信 2024-08-29 17:48:11

正如其他答案中提到的,您需要将 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 覆盖表达式工厂实现。

<context-param>
    <param-name>org.apache.myfaces.EXPRESSION_FACTORY</param-name>
    <param-value>com.sun.el.ExpressionFactoryImpl</param-value>
</context-param>
  <context-param>
    <param-name>com.sun.faces.expressionFactory</param-name>
    <param-value>com.sun.el.ExpressionFactoryImpl</param-value>
  </context-param>

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.

<context-param>
    <param-name>org.apache.myfaces.EXPRESSION_FACTORY</param-name>
    <param-value>com.sun.el.ExpressionFactoryImpl</param-value>
</context-param>
  <context-param>
    <param-name>com.sun.faces.expressionFactory</param-name>
    <param-value>com.sun.el.ExpressionFactoryImpl</param-value>
  </context-param>
似最初 2024-08-29 17:48:11

正如我在评论中提到的,这可以通过升级 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)

メ斷腸人バ 2024-08-29 17:48:11

您可以使用 JBoss EL。

它是表达式语言 2.1 的实现。但它具有允许方法参数的扩展,如您的示例所示:

<h:commandButton action="#{myBean.myAction(myParameter)}"/>

优点是您只需更改您的 web 应用程序,而不需要更改 Tomcat 的 lib 目录。

说明

  1. 下载最新版本的Seam 2
  2. 提取lib /jboss-el.jar
  3. 将其复制到 WEB-INF/lib/jboss-el.jar
  4. 在您的 web.xml 集中:

    <上下文参数>
        <参数名称>com.sun.faces.ExpressionFactory
        <参数值>org.jboss.el.E​​xpressionFactoryImpl
    
    

另请参阅调用直接方法或带 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:

<h:commandButton action="#{myBean.myAction(myParameter)}"/>

The advantage is that you only have to change your webapp and not Tomcat's lib directory.

Instructions

  1. Download the latest version of Seam 2
  2. Extract lib/jboss-el.jar
  3. Copy it to WEB-INF/lib/jboss-el.jar
  4. In your web.xml set:

    <context-param>
        <param-name>com.sun.faces.expressionFactory</param-name>
        <param-value>org.jboss.el.ExpressionFactoryImpl</param-value>
    </context-param>
    

See also Invoke direct methods or methods with parameters in EL.

千纸鹤带着心事 2024-08-29 17:48:11

将 el-api.jar 和 el-impl.jar 替换为 el-api-2.2.jar 和 el-impl-2.2.jar 可以解决该问题。

您还需要在 context.xml 中添加 context 参数

<context-param>
    <param-name>org.apache.myfaces.EXPRESSION_FACTORY</param-name>
    <param-value>com.sun.el.ExpressionFactoryImpl</param-value>
</context-param>
  <context-param>
    <param-name>com.sun.faces.expressionFactory</param-name>
    <param-value>com.sun.el.ExpressionFactoryImpl</param-value>
  </context-param>

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

<context-param>
    <param-name>org.apache.myfaces.EXPRESSION_FACTORY</param-name>
    <param-value>com.sun.el.ExpressionFactoryImpl</param-value>
</context-param>
  <context-param>
    <param-name>com.sun.faces.expressionFactory</param-name>
    <param-value>com.sun.el.ExpressionFactoryImpl</param-value>
  </context-param>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文