struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Rick Reumann <strut...@reumann.net>
Subject Re: How to iterate over two collections ?
Date Mon, 17 Nov 2003 19:01:03 GMT
Vinita Keswani wrote:

> Hello,
> 
> Could anyone please tell me if there is a workaround for iterating
> over two collections at the same time when both have the same key but
> different values?
> 
> For eg:  Descr, Cost,Volume.... Two maps one is - costMap which has
> descr and cost and another one is - volMap which has descr and
> volume.

Here's an example using JSTL that I just tested...

<%
java.util.HashMap costMap = new java.util.HashMap();
costMap.put( "foo", "costFoo" );
costMap.put( "bar", "costBar" );

java.util.HashMap volMap = new java.util.HashMap();
volMap.put( "foo", "volFoo" );
volMap.put( "bar", "volBar" );

pageContext.setAttribute("costMap", costMap );
pageContext.setAttribute("volMap", volMap );
%>

<c:forEach items="${costMap}" var="costItem">
     Cost Desc: <c:out value="${costItem.key}"/><br>
     Cost Value: <c:out value="${costItem.value}"/><br>
     Vol Value: <c:out value="${volMap[costItem.key]}"/><br>
     ----<br>
</c:forEach>
-- 
Rick


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Mime
View raw message