JSP Iterating over a map of a list when the value might be null

Posted by Brian Hoover on Stack Overflow See other posts from Stack Overflow or by Brian Hoover
Published on 2012-07-01T15:13:41Z Indexed on 2012/07/01 15:15 UTC
Read the original article Hit count: 180

Filed under:
|
|

How do I clear the value from the stack of a s:iterator?

I'm trying to iterator over a TreeMultimap with a structure like:

TreeMultimap<person, lineItems> persons;

Using something like:

<s:iterator value="attendeesForParticipantTypeEvents.asMap()">
  <div>
    <s:property value="key.name" /><br />
    <s:iterator id="currentSku" value="value">
      <s:property value="currentSku.name" /><br />
    </s:iterator>
  </div>
</s:iterator>

This works fine, except when the treeMultimap has null for lineItems, then it's taking the value from the previous iteration.

So, a structure like:

persons = {{"Person1",["Line1","line2"]},
           {"Person2",["Line3","line4"]},
           {"Person2",null}}

Renders as:

<div>
   Person1<br />
   Line1<br />
   Line2<br />
</div>
<div>
   Person2<br />
   Line3<br />
   Line4<br />
</div>
<div>
   Person3<br />
   Line3<br />
   Line4<br />
</div>

Which seems to indicate that the value isn't being cleared on each iterator. What do I need to do to handle the case where value might be null?

Thanks for your help

© Stack Overflow or respective owner

Related posts about jsp

Related posts about struts2