Search code examples
grailsgifgsp

grails gsp test evaluates to false, but block is still rendered. Why?


I'm baffled with Grails test operator.

This expression:

<g:if test="${!(preferences.displayOption.equals('ANA') || preferences.displayOption.equals('FLOP'))} ">
  ${!(preferences.displayOption.equals('ANA') || preferences.displayOption.equals('FLOP'))}
</g:if>

prints

false

How can that be? I'm printing the exact same condition I'm testing for!

even though I'm certain the test condition evaluates to 'false' because it prints false in the very next line, the statements inside the g:if are being rendered.

Anu ideas as to what's going on.


Solution

  • I think the problem is the trailing space after the final } in your test. The string "false " evaluates to true, whereas "false" will appropriately interpreted as false by the if tag.