Assume you have two objects like Foo and Bar, both of which have a getName() and getId() method. They might have a common interface or superclass, or they might be totally different.

Now assume you have an action with some method signatures like this:

public String[] getAllFoos()
public List getAllBars()

You can now write a generic 'display list' include, using a bit of property tag magic.

<webwork:property value="allFoos">
   <%@ include file="genericlist.jsp" %>
</webwork:property>

<webwork:property value="allBars"> <%@ include file="genericlist.jsp" %> </webwork:property>

What? But they're totally different objects and one is an array while the other is a list? - answer: who cares? WebWork doesn't.

The include file could look like so:

<webwork:iterator>
  <a href="viewitem.action?id=<webwork:property value="id" />">
    <webwork:property value="name">
  </a><br>
</webwork:iterator>

The iterator tag uses no value attribute, which is the equivalent of using value="." - or the top object on the stack. Here this is our String or List object.

This sort of trickery can save you lots of code, especially with many different value objects that are kind of similar. And because WW is so forgiving, they don't even need to be exactly similar.

To spin your mind more - we could have a list containing a mixture of Foo and Bar objects and the above would print them all out perfectly.

Now, what if we had a Baz object that has no getId() method, but just a getName(). With a simple <webwork:if> clause, we could then print Baz objects as well - like so:

<webwork:iterator>
  <webwork:if test="id">
    <a href="viewitem.action?id=<webwork:propertyvalue="id" />">
      <webwork:property value="name">
    </a>   
  </webwork:if>
  <webwork:else>
    <webwork:property value="name">
  </webwork:else>
  <br>
</webwork:iterator>

This will now print any 'iteratable' object (array, list, collection, XML node list, vector, enumeration iterator, map values, etc) containing any objects with a getName() method.

Note that those getName() methods could return String or any Object that is printable! WebWork will call the toString() method when printing an object if it is not a String.

Also note that in the WebWork expression language test="id" is not the same as test="id == true". test="id" is testing that id exists and is not null. Here our Baz object has not getId() method hence the if test will fail.

This functionality is available across all of WebWork's iteration tags, and not just the iterator tag.

For the sake of focussing on one issue at a time, the examples above specify url's via <a href>, it is of course far preferable to use the webwork url tag that will allow for much cleaner specification of parameters and suchlike.