This follows on from [Struts Tags] which you should read first, but beware of references to '\[0\]' and 'that'; what you really want is *top*, as illustrated below. Wiki Markup
Referencing the current value
...
No Format |
---|
Wellington, New Zealand Auckland, New Zealand Moscow, Russia Glasgow, Scotland Edinburgh, Scotland Stockholm, Sweden |
Both the country and city objects have a 'name' property. As you'd expect, the reference to 'name' on its own gives you the city name. To access the country name - effectively "hidden" by the city name - we refer to a specific position on the stack: '\[1\]'. The top of the stack, position 0, contains the current city, pushed on by the inner iterator; position 1 contains the current country, pushed there by the outer iterator. Wiki Markup
Actually, as Patrick points out in his comment on [Iteration Tags|Control Tags#ControlTags-IterationTags], the '\[n\]' notation refers to a sub-stack beginning at position n, not just the object at position n. Thus '\[0\]' is the whole stack and '\[1\]' is everything except the top object. In our example, we could have been more specific about getting the country name and said '\[1\].top.name'. Wiki Markup
Misc
If no value is specified, iterator will try to grap object from the 'top' of the stack. If it is not iterable, ClassCastException will be thrown in the process. @see com.opensymphony.webwork.views.jsp.IteratorTag#doStartTag