It's a trap! OGNL / ww:if pitfall

smartr <[email protected]> Wed, 27 Dec 2006 12:34:20 CST
Newsgroups gmane.comp.java.open-symphony.webwork
Message-ID <16623333.1167244560651.JavaMail.os-j2ee@opensymphony01.managed.contegix.com>
[code]
<ww:if test="%{myListOrMap.isEmpty}">
   foo
</ww:if>
<ww:elseif test="%{!myListOrMap.isEmpty}">
   bar
</ww:elseif>
<ww:else>
   baz <br/>
</ww:else>
<ww:if test="%{(myListOrMap == null)}">
  It's a Trap!
</ww:if>
[/code]

I suppose this is more to demonstrate behavior that I think one can easily bump into, and to put it into the minds of someone who'd write documentation. The point being is that if you have a getter for a map or list called myListOrMap in your action, and if myListOrMap was not instantiated, you would get:
baz
It's a Trap!
...
In a similiar light, if myListOrMap was instantiated, but has nothing in it, the null test would evaluate to false - so... I suppose my point is it's a confusing pitfall with understandable behavior.
---------------------------------------------------------------------
Posted via Jive Forums
http://forums.opensymphony.com/thread.jspa?threadID=55613&messageID=110596#110596