Explain the use of <logic:iterate> tag in struts application
The tag is utilized for repeating the nested body content over a collection. Every element / object in a specified collection – which must be any one of – Iterator, Collection and Map or even an array – and their contents are nested in this tag.
The iterable collection must be specified in any one of the following methods:
- As a runtime expression that is specified as a value of the ‘collection’ attribute
- As a JSP bean that is specified by the ‘name’ attribute
- As the property that is specified by the ‘property’ of the JSP bean specified by the ‘name’ attribute.
Usually, every object that is exposed by the iterate tag is an object of the underlying collection that is to iterate over. In case a Map is to iterate, the exposed object should be of the type Map.Entry, which has two properties – i) key – the key under which the object / element is stored in a Map – ii) value – the value of corresponding key.
The following
example depicts the usage of Hashtable that is to iterate:
<logic:iterate id="account" name="bankaccountnums">
Next account no is <bean:write name="account" property="value"/>
</logic:iterate>