Websphere fails on using reserved words in EL
-
19-06-2021 - |
Question
I've got a JSF1.2 application which deploys fine on Tomcat6 and Tomcat7. So far so good.
One of the pages contains the following property on a h:inputText:
disabled="#{quoteFinance.quoteSaved or quoteRequest.quoteDisabled or setting.protected}"
This validates and works fine on aforementioned Tomcat servers. However, websphere8 believes this is a problem and throws the following error:
disabled="#{quoteFinance.quoteSaved or quoteRequest.quoteDisabled or setting.protected}" [protected] is not a valid Java identifier
at com.sun.facelets.tag.TagAttribute.getValueExpression(TagAttribute.java:259)
at com.sun.facelets.tag.jsf.ComponentRule$ValueExpressionMetadata.applyMetadata(ComponentRule.java:69)
at com.sun.facelets.tag.MetadataImpl.applyMetadata(MetadataImpl.java:36)
at com.sun.facelets.tag.MetaTagHandler.setAttributes(MetaTagHandler.java:76)
Cause:
javax.el.ELException: [protected] is not a valid Java identifier
at org.apache.el.parser.AstDotSuffix.setImage(AstDotSuffix.java:45)
at org.apache.el.parser.ELParser.DotSuffix(ELParser.java:1067)
at org.apache.el.parser.ELParser.ValueSuffix(ELParser.java:1033)
at org.apache.el.parser.ELParser.Value(ELParser.java:978)
at org.apache.el.parser.ELParser.Unary(ELParser.java:948)
at org.apache.el.parser.ELParser.Multiplication(ELParser.java:712)
at org.apache.el.parser.ELParser.Math(ELParser.java:632)
at org.apache.el.parser.ELParser.Compare(ELParser.java:444)
at org.apache.el.parser.ELParser.Equality(ELParser.java:338)
at org.apache.el.parser.ELParser.And(ELParser.java:282)
I had a similar issue with #{msg.continue}
which is perfectly fine, but because continue is a reserved word, WAS8 throws me an error.
- Why does websphere not accept this while the code is working perfectly?
- How can I resolve this problem?
Many thanks!
Solution
From the Expression Language 2.2 spec:
An identifier is constrained to be a Java identifier - e.g., no
-
, no/
, etc.
protected
can't be used as an identifier in Java as it is reserved.
This restriction applied in EL 2.1 too, so it was likely a bug in your old platform's EL parser that this ever worked.
OTHER TIPS
This behaviour is as per EL specification. You need to rename the property name to something which isn't a Java literal, or you need to use the brace notation so that it can be referenced as String
.
#{setting['protected']}
and
#{msg['continue']}
This should have failed in Tomcat 7 as well, perhaps you were using a rather old version of Tomcat 7. This was been "fixed" somewhere between 7.0.0 and 7.0.10. It's currently already at 7.0.28.
"protected" is a java reserved word too! just like "continue"