FAQ
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.

Please help

Vinita


---------------------------------
Do you Yahoo!?
Protect your identity with Yahoo! Mail AddressGuard

Search Discussions

  • Brice Ruth at Nov 17, 2003 at 6:29 pm
    You could loop over one collection, exposing the varStatus, which
    contains the key, and use the key to look up in the second map ... I think?

    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.

    Please help

    Vinita


    ---------------------------------
    Do you Yahoo!?
    Protect your identity with Yahoo! Mail AddressGuard
    --
    Brice D. Ruth
    Sr. IT Analyst
    Fiskars Brands, Inc.



    ---------------------------------------------------------------------
    To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
    For additional commands, e-mail: struts-user-help@jakarta.apache.org
  • Kris Schneider at Nov 17, 2003 at 6:40 pm
    With JSTL:

    <c:forEach var="entry" items="${costMap}">
    <c:out value="${entry.value}"/>
    <c:out value="${volMap[entry.key]}"/>
    </c:forEach>

    Quoting Brice Ruth <bruth@fiskars.com>:
    You could loop over one collection, exposing the varStatus, which
    contains the key, and use the key to look up in the second map ... I think?

    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.

    Please help

    Vinita


    ---------------------------------
    Do you Yahoo!?
    Protect your identity with Yahoo! Mail AddressGuard
    --
    Brice D. Ruth
    Sr. IT Analyst
    Fiskars Brands, Inc.
    --
    Kris Schneider
    D.O.Tech <http://www.dotech.com/>

    ---------------------------------------------------------------------
    To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
    For additional commands, e-mail: struts-user-help@jakarta.apache.org
  • Vinita Keswani at Nov 17, 2003 at 6:46 pm
    Thanks but in any case I have to create an iterator to loop thru the maps.What I want to do is to have one loop and to pick up value entries from another - yes may be I can try using lookups using key???

    Kris Schneider wrote:With JSTL:






    Quoting Brice Ruth
    :
    You could loop over one collection, exposing the varStatus, which
    contains the key, and use the key to look up in the second map ... I think?

    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.

    Please help

    Vinita


    ---------------------------------
    Do you Yahoo!?
    Protect your identity with Yahoo! Mail AddressGuard
    --
    Brice D. Ruth
    Sr. IT Analyst
    Fiskars Brands, Inc.
    --
    Kris Schneider
    D.O.Tech

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



    ---------------------------------
    Do you Yahoo!?
    Protect your identity with Yahoo! Mail AddressGuard
  • Kris Schneider at Nov 17, 2003 at 7:05 pm
    I think the code I provided does what you were asking for, but maybe I'm missing
    something. Perhaps adding comments to my example will help:

    <%-- iterate through costMap, "entry" will be an instance of Map.Entry --%>
    <%-- Map.Entry exposes two properties: "key" and "value" --%>
    <c:forEach var="entry" items="${costMap}">

    <%-- output value for costMap entry --%>
    <c:out value="${entry.value}"/>

    <%-- output value for volMap entry --%>
    <c:out value="${volMap[entry.key]}"/>

    </c:forEach>

    Quoting Vinita Keswani <vinitakeswani@yahoo.com>:
    Thanks but in any case I have to create an iterator to loop thru the
    maps.What I want to do is to have one loop and to pick up value entries from
    another - yes may be I can try using lookups using key???

    Kris Schneider wrote:With JSTL:






    Quoting Brice Ruth
    :
    You could loop over one collection, exposing the varStatus, which
    contains the key, and use the key to look up in the second map ... I think?
    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.

    Please help

    Vinita


    ---------------------------------
    Do you Yahoo!?
    Protect your identity with Yahoo! Mail AddressGuard
    --
    Brice D. Ruth
    Sr. IT Analyst
    Fiskars Brands, Inc.
    --
    Kris Schneider
    D.O.Tech
    --
    Kris Schneider
    D.O.Tech <http://www.dotech.com/>

    ---------------------------------------------------------------------
    To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
    For additional commands, e-mail: struts-user-help@jakarta.apache.org
  • Vinita Keswani at Nov 17, 2003 at 9:06 pm
    Thanks again...

    Yes I have to lookup using the key ..that will work fine..Thanks again.

    Kris Schneider wrote:
    I think the code I provided does what you were asking for, but maybe I'm missing
    something. Perhaps adding comments to my example will help:













    Quoting Vinita Keswani :
    Thanks but in any case I have to create an iterator to loop thru the
    maps.What I want to do is to have one loop and to pick up value entries from
    another - yes may be I can try using lookups using key???

    Kris Schneider wrote:With JSTL:






    Quoting Brice Ruth
    :
    You could loop over one collection, exposing the varStatus, which
    contains the key, and use the key to look up in the second map ... I think?
    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.

    Please help

    Vinita


    ---------------------------------
    Do you Yahoo!?
    Protect your identity with Yahoo! Mail AddressGuard
    --
    Brice D. Ruth
    Sr. IT Analyst
    Fiskars Brands, Inc.
    --
    Kris Schneider
    D.O.Tech
    --
    Kris Schneider
    D.O.Tech

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


    ---------------------------------
    Do you Yahoo!?
    Protect your identity with Yahoo! Mail AddressGuard
  • Rick Reumann at Nov 17, 2003 at 7:01 pm

    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

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupuser @
categoriesstruts
postedNov 17, '03 at 6:11p
activeNov 17, '03 at 9:06p
posts7
users4
websitestruts.apache.org
irc#struts

People

Translate

site design / logo © 2022 Grokbase