Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Changed old ww: naming to s:

...

The simple examples print out values from the list using the property tag, which uses the value at the top of the stack by default:

No Format
Days:
<ul>
<ww<s:iterator value="days">
    <li><ww<li><s:property/>
</wws:iterator>
</ul>

But if you're doing anything other than print the value, you probably need to refer to it specifically. Do this:

No Format
Most days:
<ul>
<ww<s:iterator value="days">
    <ww<s:if test="top != 'Monday'">
        <li><ww<li><s:property/>
    </wws:if>
</wws:iterator>
</ul>

Iterating over a list of objects

No Format
<ww<s:iterator value="employees">
    <ww<s:property value="name"/> is the <ww<s:property value="jobTitle"/><br>
</wws:iterator>

For 'name' and 'jobTitle' you could be more explicit and write 'top.name' and 'top.jobTitle', as 'top' refers to the object on the top of the stack. It's not necessary here, but it is in the next example.

Iterating over a list of lists

No Format
<table>
    <ww<s:iterator value="grid">
        <tr>
        <ww<s:iterator value="top">
            <td><ww<td><s:property/></td>
        </wws:iterator>
        </tr>
    </wws:iterator>
</table>

The trick here is to use 'top' as the value for the inner iterator. This example probably uses a two-dimensional array, but you can use the pattern for any list of lists.

...

In this example, 'countries' is a list of country objects, each of which has a name and a list of cities. Each city has a name.

No Format
<ww<s:iterator value="countries">
    <ww<s:iterator value="cities">
        <ww<s:property value="name"/>, <ww<s:property value="[1].name"/><br>
    </wws:iterator>
</wws:iterator>

The output looks like

...