Using the c:forEach
custom tag, it is easy to iterate over collections including map's.
Altough you have to keep in mind that the resulting value is a MapItem.
The MapItem has 2 properties named key
and value
.
These properties can be treated as javabeans theirselves, hence its properties being retrieved according to the javabean specification.
Hereunder follows a sample that iterates over a map, the key is of type String and the value of a type that complies to the javabean specification:
<table>The output of the above sample is:
<c:forEach var="item" items="myMap">
<tr>
<td>
<c:out value="${item.key}"/>
</td>
<td>
<c:out value="${item.value.givenName}"/>
</td>
<td>
<c:out value="${item.value.surName}"/>
</td>
</tr>
</c:forEach>
</table>
1 | John | Doe |
2 | Jane | Doe |
3 | Johnny jr. | Doe |
7 comments:
Thanks! This is highly helpful
Thank you for your code snippet.
Very helpful.
Very clever advice.
Now my JSP web working fine.
Thanks from Europe.
Simple but extremelly useful. Thanks!
Right to the spot. Exactly what I needed. Big Thanks.
Thanks, was struggling with the same problem for quite a while. :-)
Thank you very much for the advice. I can see that this post is pretty old but still very much relevant and useful.
Post a Comment