Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

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

Currenty I have a web project with JSF 1.2 and Facelets running in tomcat 6.0.18.0. I decided to upgrade the servlet container, thus i deployed in tomcat 7 and all seemed ok until we hit one view using my custome facelet functions.

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:
"}" ...
"." ...
"[" ...

This error occurs when parsing the following code:

<ui:repeat var="object" value="#{objects}">
<ui:fragment rendered="#{pz:instanceof(object,'com.project.domain.MyClass')}">
...

If i understand correctly it throws an error because of the colon in the expression . I have tracked it down to the jasper-el that come with in the tomcat/lib directory, and if I replace jasper.jar and jasper-el.jar with the ones from tomcat 6.0.18 everythign works well.

Has anyone else had this problem before upgrading their tomcat? And How did they resolve it? Could I deploy in production tomcat 7 with these jasper jar from tomcat 6, or could this cause further problems.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

This is actually a misleading exception. It has a different underlying cause. The function name instanceof is invalid.

The EL 2.2 specification says the following:

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.

and

1.19 Collected Syntax

...

Identifier ::= Java language identifier

...

Where the Java language identifier stands for keywords like instanceof, if, while, class, return, static, new, etc. They may not be used as variable/function names in EL. In case you have properties with those names, use the brace notation instead like so #{bean['class'].simpleName} instead of #{bean.class.simpleName}.

This was been fixed in Tomcat 7.0.4 or somewhere near before this version as indicated by issue 50147 wherein someone else pointed out the same problem as you have. So, to solve your problem, you have to rename your EL function name to for example isInstanceOf or something.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...