以下JSF代码段:
<p:dataTable value="#{userbean.getAll()}" var="user">
引发此异常:
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)
这是如何引起的?如何解决?
答案 0 :(得分:12)
如果您的环境不支持EL 2.2,则会发生这种情况。使用像这样的括号/参数调用直接方法
value="#{userbean.getAll()}"
仅从EL 2.2开始支持,它与Servlet 3.0密切相关。如果您遇到此异常,那么这只能意味着您没有部署到与Servlet 3.0兼容的容器,或者您的webapp的web.xml
未声明为符合Servlet 3.0,或者您的webapp {{1}任意下载的servletcontainer特定的JAR文件都来自于完全不同的servletcontainer make / version,它不符合EL 2.2。
基本上有两种解决方案:
使用EL 2.1兼容语法,这适用于Servlet 2.5兼容容器:
/WEB-INF/lib
升级到Servlet 3.0兼容容器(Tomcat 7,Glassfish 3,JBoss AS 6等),或者修复value="#{userbean.all}"
以遵守Servlet 3.0。
您还应该确保您的网络应用web.xml
不包含任何特定于servlet容器的库,例如/WEB-INF/lib
和朋友(另请参阅this related question)
请注意,这根本不是JSF问题。您从el-api.jar
/ javax.el
包中获得了例外,而不是来自org.apache.el
/ javax.faces
包。这意味着它是一个EL问题。它基本上是说你的EL语法错了。它遇到了一个com.sun.faces
,它没想到。之后清楚地列出了预期的字符/运算符。