org.apache.el.parser.ParseException: Encountered “(” at line X, column Y. Was expecting one of […]

不羁岁月 提交于 2019-11-28 05:11:23

问题


The below JSF snippet:

<p:dataTable value="#{userbean.getAll()}" var="user">

Throws this exception:

Encountered "(" at line 1, column 18. Was expecting one of: "}" ... "." ... "[" ... ">" ... "gt" ... "<" ... "lt" ... ">=" ... "ge" ... "<=" ... "le" ... "==" ... "eq" ... "!=" ... "ne" ... "&&" ... "and" ... "||" ... "or" ... "*" ... "+" ... "-" ... "/" ... "div" ... "%" ... "mod" ... 
org.apache.el.parser.ParseException: Encountered "(" at line 1, column 18. 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)
    at org.apache.el.lang.ExpressionBuilder.build(ExpressionBuilder.java:150)
    at org.apache.el.lang.ExpressionBuilder.createValueExpression(ExpressionBuilder.java:194)
    at org.apache.el.ExpressionFactoryImpl.createValueExpression(ExpressionFactoryImpl.java:68)
    at com.sun.faces.facelets.el.ELText$ELTextVariable.apply(ELText.java:203)
    at com.sun.faces.facelets.compiler.AttributeInstruction.apply(AttributeInstruction.java:101)
    at com.sun.faces.facelets.compiler.UIInstructionHandler.apply(UIInstructionHandler.java:141)
    at javax.faces.view.facelets.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:98)
    at javax.faces.view.facelets.DelegatingMetaTagHandler.applyNextHandler(DelegatingMetaTagHandler.java:137)
    at com.sun.faces.facelets.tag.jsf.ComponentTagHandlerDelegateImpl.apply(ComponentTagHandlerDelegateImpl.java:196)
    at javax.faces.view.facelets.DelegatingMetaTagHandler.apply(DelegatingMetaTagHandler.java:120)
    at javax.faces.view.facelets.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:98)

How is this caused and how can I solve it?


回答1:


That can happen if your environment doesn't support EL 2.2. Invoking direct methods with parentheses/arguments like this

value="#{userbean.getAll()}" 

is only supported since EL 2.2, which goes hand in hand with Servlet 3.0. If you're getting this exception, then that can only mean that you're not deploying to a Servlet 3.0 compatible container, or that your webapp's web.xml is not declared conform Servlet 3.0, or that your webapp's /WEB-INF/lib is littered with arbitrarily downloaded servletcontainer-specific JAR files originating from a completely different servletcontainer make/version which doesn't comply EL 2.2.

There are basically 2 solutions:

  1. Use EL 2.1 compatible syntax, this works on Servlet 2.5 compatible containers:

    value="#{userbean.all}" 
    
  2. Upgrade to a Servlet 3.0 compatible container (Tomcat 7, Glassfish 3, JBoss AS 6, etc), or fix your web.xml to comply Servlet 3.0.

You should also make absolutely sure that your webapp's /WEB-INF/lib does not contain any servletcontainer-specific libraries such as el-api.jar and friends (see also this related question).

Please note that this is not a JSF problem at all. You got an exception from javax.el/org.apache.el package, not from javax.faces/com.sun.faces package. This means that it's an EL problem. It's basically saying that your EL syntax is wrong. It encountered an ( where it didn't expect that. The expected characters/operators are clearly listed thereafter.

See also:

  • Invoke direct methods or methods with arguments / variables / parameters in EL
  • How to call a method with a parameter in JSF
  • Our EL wiki page


来源:https://stackoverflow.com/questions/17836525/org-apache-el-parser-parseexception-encountered-at-line-x-column-y-was-ex

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