Eclipse gives too many false errors and warnings o

2019-01-27 17:27发布

问题:

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?

回答1:

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.

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”


回答2:

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