3

I am trying to evaluate EL expression (method expression?) that returns a value (String) if that value is equal to "bar" then I would like to render the tag.

<p:tab rendered="#{bean.getAnswer('foo').answer == "bar"}" />

However I get following error message.

Invalid location of text ("}") in tag.

What would be the right syntax to use?

DaeYoung
  • 1,161
  • 6
  • 27
  • 59

2 Answers2

12

Edit: Remove the double quotes arround bar, it's also such a String. You can use == also to compare Strings. I preffer eq for more readable.

<p:tab rendered="#{bar eq bean.getAnswer('foo')}" />

<p:tab rendered="#{bar == bean.getAnswer('foo')}" />

All operators can you found here. http://docs.oracle.com/javaee/6/tutorial/doc/bnaik.html

THX @Jasper de Vries

jklee
  • 2,198
  • 2
  • 15
  • 25
0

The problem I see here is the use of "" for the value bar, as it is conflicting with the outer "".

Have it wrapped inside single quotes, like so 'bar'.

Hope this helps.

UPDATE:

Using 'eq' with String makes it more readable. However, == works too.

Prathap
  • 178
  • 1
  • 1
  • 9
  • You **can** use `==`. See also [Should I choose == or eq for comparing string in EL?](http://stackoverflow.com/questions/10796350/should-i-choose-or-eq-for-comparing-string-in-el). – Jasper de Vries Dec 16 '16 at 16:02
  • Well I didn't say == wouldn't work. Using eq just makes it more readable/applicable when used with Strings. Anyway, got your point! :) – Prathap Dec 16 '16 at 16:36