tags:

views:

73

answers:

2

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.

+3  A: 

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.

Ben Williams
Thanks! It didn't occur to me that it's actually looking for the string "false"! I figured that's just the .asString() rendering of a boolean.
ראובן
+2  A: 

Try removing the extra space after the closing } in the test attribute. You can view the generated groovy source by adding "?showSource=true" to the url in development mode. The extra space causes it to create a String "false " which evaluates to true.

FlareCoder