Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 980
adbdkb Avatar asked Feb 19 '15 12:02

adbdkb


2 Answers

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:

  • Method must have signature "String method() ...[etc]..." but has signature "void method()"
  • Eclipse errors on #{component.valid}: "valid cannot be resolved as a member of component”
like image 161
BalusC Avatar answered Nov 03 '22 05:11

BalusC


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'}">

like image 4
JoseA Avatar answered Nov 03 '22 06:11

JoseA