jsf - javax.el.E​​LException : Failed to parse the expression [{pz:instanceof(object ,'com.project.domain.MyClass' )}]

标签 jsf facelets el tomcat7

目前我有一个在 tomcat 6.0.18.0 中运行的带有 JSF 1.2 和 Facelets 的 Web 项目。我决定升级 servlet 容器,因此我部署在 tomcat 7 中,一切似乎都很好,直到我们使用我的自定义 facelet 函数点击了一个 View 。
javax.el.ELException: Failed to parse the expression [{pz:instanceof(object,'com.project.domain.MyClass')}]

Caused by: org.apache.el.parser.ParseException: Encountered " ":" ": "" at line 1, column 5. Was expecting one of:
"}" ...
"." ...
"[" ...

解析以下代码时出现此错误:
<ui:repeat var="object" value="#{objects}">
<ui:fragment rendered="#{pz:instanceof(object,'com.project.domain.MyClass')}">
...

如果我理解正确,它会因为表达式中的冒号而引发错误。我已将其追踪到 tomcat/lib 目录中附带的 jasper-el,如果我将 jasper.jar 和 jasper-el.jar 替换为来自 tomcat 6.0.18 的所有内容,则一切正常。

有没有其他人在升级他们的 tomcat 之前遇到过这个问题?他们是如何解决的?
我可以使用来自 tomcat 6 的这些 jasper jar 在生产 tomcat 7 中部署,或者这可能会导致进一步的问题。

最佳答案

这实际上是一个误导性的异常(exception)。它有一个不同的根本原因。函数名 instanceof是无效的。

EL 2.2 specification说如下:

1.14 Reserved Words

The following words are reserved for the language and must not be used as identifiers.

    and   eq     gt     true   instanceof
    or    ne     le     false  empty
    not   lt     ge     null   div        mod

Note that many of these words are not in the language now, but they may be in the future, so developers must avoid using these words.





1.19 Collected Syntax

...

Identifier ::= Java language identifier

...



Java 语言标识符代表关键字,如 instanceof , if , while , class , return , static , new等。它们不能用作 EL 中的变量/函数名称。如果您有这些名称的属性,请使用大括号表示法,就像这样 #{bean['class'].simpleName}而不是 #{bean.class.simpleName} .

issue 50147 所示,此问题已在 Tomcat 7.0.4 或此版本之前的某个附近修复。其中其他人指出了与您相同的问题。因此,要解决您的问题,您必须将 EL 函数名称重命名为例如 isInstanceOf或者其他的东西。

关于jsf - javax.el.E​​LException : Failed to parse the expression [{pz:instanceof(object ,'com.project.domain.MyClass' )}],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7866769/

相关文章:

javascript - 两个几乎相同的页面之一缺少 CSS 和 Javascript

jsf - 如何在jsf页面中设置bean属性值?

java - 为 PrimeFaces remoteCommand 生成并使用唯一名称

java - JSF 2.0 : Empty operator doesn't work with param

jsp - javax.el.E​​LException : Cannot convert [light, amber, brown, dark] 类 java.util.ArrayList 到类 [Ljava.lang.String;

java - JSF EL 条件

java - 在哪里缓存: Database cache or App server using SessionScoped managed beans?

java - richfaces 3.3.x 中的客户端验证

java - 使用 Qualifier 和 InjectionPoint 作为 @HttpParam 在 CDI/WELD 中实现 @RequestParam

html - 使用 EL 访问对象属性时进行 null 检查的必要性