views:

1554

answers:

4

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/&lt;/url&gt;
  </repository>
  <repository>
    <id>jboss</id>
    <url>http://repository.jboss.com/maven2/&lt;/url&gt;
  </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>
A: 

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
jamiebarrow
Removing jasper-el.jar fixes my issue. Anybody know of side effects of this?
jamiebarrow
I assume that jasper-el.jar is just the implementation of the el-api, so it should be fine? It would be great if someone can confirm my thoughts :)
jamiebarrow
+1  A: 

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)

jamiebarrow
Worked for me, thanks!
waxwing
A: 

Hi,

This systematically fails for me with "java.lang.NoClassDefFoundError: org/apache/el/ExpressionFactoryImpl" (which is the original tomcat impl class, while Glassfish's is com.sun.something)

  • which el-impl-2.2 are you using ? (I grabbed mine from the java.net maven2 repository with the coordinates mention in the original question)
  • if you're using glassfish's jar, any idea where Tomcat says it wants to use its own el-impl classes ? A grep in the whole tomcat for "ExpressionFactoryImpl" only points out the el-api and el-impl jars, so I've no idea where it defines which class to use...

(edit: well, turns out that it's simply hardcoded in the JspUtil, PageInfo and JspApplicationContextImpl classes; i'd be curious to hear how you got that running)

Grégory Joseph
Did you remove jasper-el.jar from the tomcat lib folder?
jamiebarrow
I did, but given the findings of my "edit", I don't think there's any way this could ever work, the link to org/apache/el/ExpressionFactoryImpl being hardcoded in classes of jasper.jar
Grégory Joseph
I got this issue myself. I was able to solve it by creating a jar that contained my own implementation of org.apache.el.ExpressionFactoryImpl that simply delegates to an instance of com.sun.el.ExpressionFactoryImpl. Haven't found any issues yet..
waxwing
thanks @waxwing; a bit hackish, but if it works, it works :)
Grégory Joseph
I still had this error until I dropped the el-impl-2.2.jar into my web-inf/lib folder. I am still getting the NoClassDef error, but the container is able to find the impl jar and use that. It's also worth noting that Tomcat 7 implements 2.2 EL.
ClutchDude
A: 

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>
Lawrence McAlpin