Eclipse gives too many false errors and warnings on EL expressions in JSF files
Asked Answered
D

2

13

I have run into a weird situation. I have an application which was originally developed in RAD and uses a construct like

rendered="#{bean.show and user.can('foo')}"

Our developers use mix of RAD and Eclipse Juno / Kepler. So we need to make the code work in both the environments.

In RAD, the above line does not generate any errors. When I export the project as archive and import it into Eclipse Juno, it generates this error

Cannot apply expression operators to method bindings

Our environment is Websphere 8.5, RAD / Eclipse, JSF 2.1

How can I fix this?

Disaccredit answered 19/2, 2015 at 12:1 Comment(0)
E
20

In general, if you face a false EL validation error in a JSF file in Eclipse, try peeking around in Window > Preferences > Web > JavaServer Faces Tools > Validation and tune some settings currently (unnecessarily) set at Error.

enter image description here

Your particular problem is triggered by "Applying operator to method binding" which indeed defaults to Error. If upgrading Eclipse to most recent version is somehow not an option, setting it back to Warning should tone down it.

After all, EL validation in Eclipse is quite an epic fail. It seems like it's using regular expressions to validate EL syntax instead of a true stack based parser like as EL itself is doing. There are several entries below "Type Coercion Problems" and "Type Assignment Problems" which are unnecessarily set to Error and known to cause false errors.

See also:

Electrophorus answered 19/2, 2015 at 12:39 Comment(3)
Thanks BalisC. I will check the validation settings. But I am still confused as to why the error goes away when I either a) Use $ instead of # or b) Change the order. Would you be abel to explain tha tpart to me?Disaccredit
This error popped up on me my projects with a fresh install of Eclipse Mars.1. So Eclipse seems to have changed it's default here to ERROR again.Haiku
I opened bugs.eclipse.org/bugs/show_bug.cgi?id=540785 for this. I still reproduce with Eclipse 2018-09.Caulicle
C
5

I had the same error with any of these statements:
<h:panelGroup rendered="#{!bean.isValid(obj)}"> <h:panelGroup rendered="#{not bean.isValid(obj)}">

I resolved the error by changing the statement as follows:
<h:panelGroup rendered="#{bean.isValid(obj) == false}">

I found yet another example that resolved the problem:
<ui:fragment rendered="#{bean.isValid(obj) eq 'false'}">

Cobby answered 14/3, 2018 at 14:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.