23

The Eclipse Facelet HTML Validator reports an error "Cannot apply expression operators to method bindings" for the following line:

<ui:fragment rendered="#{!empty managedBean.getSomething('ENUM_VALUE', someInt)}">

I found this in the Juno help (I'm using Kepler):

Applying operator to method binding
#{bean.action * 5}
If bean.action indicates a method "action()" on bean, then it is not legal EL to treat its result as a value. In the example, multiplying action by 5 attempts treat it is as a value.

I'm having trouble understanding why it's not legal to treat its result as a value? What's the correct way to write the EL then? Thanks!

Candice
  • 321
  • 1
  • 5
  • 9
  • 1
    See also: http://stackoverflow.com/q/28605864/1725096 – Jens Piegsa Dec 03 '15 at 15:11
  • The link above, in which BalusC says "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." – Pixelstix May 06 '21 at 20:21

2 Answers2

25

If you like you can hide the error message by setting

Window -> Preferences -> Web -> JavaServer Faces Tool -> Validation -> General Problems

the value Applying method operator to binding to Ignore.

blo0p3r
  • 6,790
  • 8
  • 49
  • 68
pasql
  • 3,815
  • 5
  • 23
  • 33
  • 4
    Well, this is a fine mitigation for the Eclipse issue, but it does not show "the correct way to write the EL". – zb226 Jan 15 '15 at 15:03
23

Have you tried putting paranthesis around your method. Like this:

#{!empty (managedBean.getSomething('ENUM_VALUE', someInt))}

This way JSF evaluates the method and then checks for null or empty.

I am no expert in JSF, but I had the same problem in one of the similar expression:

#{some_method() == 0 and some_other_method() eq 'some value'}

I saw the same issue shown by Eclipse but the page was running correctly. After I put paranthesis around both of my expressions, Eclipse did not show that error.

zb226
  • 9,586
  • 6
  • 49
  • 79
Rash
  • 7,677
  • 1
  • 53
  • 74
  • 2
    I am learning here and would like to know the reason for downvote please. Thanks. – Rash Oct 07 '14 at 18:14
  • 2
    I rechecked my answer. I recreated the situation. Eclipse does not show error when your method expression is under parantheseis. Please tell me why you downvoted my answer ? – Rash Oct 08 '14 at 19:16
  • This worked! thanks. Idk why you were downvoted originally. – Ced Jan 08 '16 at 15:26
  • This is still present in Eclipse Neon.3 Release (4.6.3). But the code compile and run perfectly. – Ranuka Jun 19 '17 at 09:12