Repeats the nested body content of this tag once for every element
of the specified collection, which must be an Iterator
,
a Collection
, a Map
(whose values are to be
iterated over), or an array. The collection to be iterated over must be
specified in one of the following ways:
collection
attribute.name
attribute.property
, of the
JSP bean specified by the name
attribute.The collection to be iterated over MUST conform to one of the following requirements in order for iteration to be successful:
java.util.Collection
, including
ArrayList
and Vector
.java.util.Enumeration
.java.util.Iterator
.java.util.Map
, including
HashMap
, Hashtable
, and
TreeMap
. NOTE - See below for
additional information about accessing Maps.Normally, each object exposed by the iterate tag is an element
of the underlying collection you are iterating over. However, if you
iterate over a Map
, the exposed object is of type
Map.Entry
that has two properties:
key
- The key under which this item is stored in the
underlying Map.value
- The value that corresponds to this key.So, if you wish to iterate over the values of a Hashtable, you would implement code like the following:
<logic:iterate id="element" name="myhashtable">
Next element is <bean:write name="element" property="value"/>
</logic:iterate>
If the collection you are iterating over can contain null
values, the loop will still be performed but no page scope attribute
(named by the id
attribute) will be created for that loop
iteration. You can use the <logic:present>
and
<logic:notPresent>
tags to test for this case.