开发者

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.equ开发者_如何学Goals('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.


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜