Grokbase Groups Struts user May 2005
FAQ
Hi all,

Let's say I have two collections, A, and B. Is there a way to iterate
over multiple collections with something like logic:iterate?

i.e

<logic:iterate>
${rowA.name}
${rowB.value}
</logic:iterate>

--
Titus Barik (titus@barik.net)
http://www.barik.net

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

Search Discussions

  • Wendy Smoak at May 23, 2005 at 11:42 pm
    From: "Titus Barik" <titus@barik.net>
    Let's say I have two collections, A, and B. Is there a way to iterate
    over multiple collections with something like logic:iterate?
    If you know they're the same size and in the same order, (should be the case
    with List,) how about iterating over one with <c:forEach varStatus="status">
    and using ${status.count} to address the second List.

    Can you change the design? If the items in both collections really belong
    together, try to store them together so you don't have to jump through hoops
    like this.

    --
    Wendy Smoak


    ---------------------------------------------------------------------
    To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
    For additional commands, e-mail: user-help@struts.apache.org
  • Pushkala_iyer at May 24, 2005 at 2:21 pm
    A related question, so I thought I'll post it to this thread.

    The data structure I use is a HashMap, whose values are other HashMaps.
    Like so:

    OuterMap
    OuterKey1: InnerMap1
    InnerKey11: Value11
    InnerKey12: Value12
    OuterKey2: InnerMap2
    InnerKey21: Value21
    InnerKey22: Value22

    I'm trying to nest two logic:iterate tags to print out the keys in the
    outer map and the values in the inner Map.

    What I'm trying to do is something like this:

    <logic:iterate id="myOuterMap" name="myForm" property="myOuterMap">
    <tr>
    <td><bean:write name="myOuterMap" property="key"/></td>
    <logic:iterate id="myInnerMap" name="myForm" property="myInnerMap">
    <td><bean:write name="myInnerMap" property="value"/></td>
    </logic:iterate>
    </tr>
    </logic:iterate>

    This has a problem, because, it needs the innerMap attribute set in the
    request - however, this always gets the same value, probably because of
    the way I'm setting it in my Action.

    1) I probably need a list of innerMaps in my form, but I'm not sure how
    to do this.

    2) If I try to print the value using the outerMap alone, like so,
    <td><bean:write name="MyOuterMap" property="value"/></td> I'm not
    sure how I can format this in the way that only the values are seen.

    Does anyone have any pointers?

    Thanks,
    PS

    -----Original Message-----
    From: Wendy Smoak
    Sent: Monday, May 23, 2005 6:42 PM
    To: Struts Users Mailing List
    Subject: Re: logic:iterate multiple collections

    From: "Titus Barik" <titus@barik.net>
    Let's say I have two collections, A, and B. Is there a way to iterate
    over multiple collections with something like logic:iterate?
    If you know they're the same size and in the same order, (should be the
    case with List,) how about iterating over one with <c:forEach
    varStatus="status"> and using ${status.count} to address the second
    List.

    Can you change the design? If the items in both collections really
    belong together, try to store them together so you don't have to jump
    through hoops like this.

    --
    Wendy Smoak



    ---------------------------------------------------------------------
    To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
    For additional commands, e-mail: user-help@struts.apache.org
  • Wendy Smoak at May 24, 2005 at 4:04 pm
    From: <Pushkala_Iyer@Dell.com>
    The data structure I use is a HashMap, whose values are other HashMaps.

    I'm trying to nest two logic:iterate tags to print out the keys in the
    outer map and the values in the inner Map.
    <c:forEach var="outerMapEntry" items="${outerMap}">
    <c:out value="${outerMapEntry.key}"/>
    <c:forEach var="innerMapEntry" items="${outerMapEntry.value}" >
    <c:out value="${innerMapEntry.value}"/>
    </c:forEach>
    </c:forEach>

    See http://wiki.wendysmoak.com/cgi-bin/wiki.pl?JSTLNestedMapIterate for test
    code.

    --
    Wendy Smoak



    ---------------------------------------------------------------------
    To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
    For additional commands, e-mail: user-help@struts.apache.org
  • Pushkala_iyer at May 24, 2005 at 7:21 pm
    Thanks! That worked, and is also much easier to understand.

    This is probably a newbie question: How / when does one choose between
    using JSTL / Struts Tags?
    Is there any reason to choose Struts tags over JSTL?

    Thanks,
    PS

    -----Original Message-----
    From: Wendy Smoak
    Sent: Tuesday, May 24, 2005 11:02 AM
    To: Struts Users Mailing List
    Subject: Re: logic:iterate multiple collections

    From: <Pushkala_Iyer@Dell.com>
    The data structure I use is a HashMap, whose values are other HashMaps.
    I'm trying to nest two logic:iterate tags to print out the keys in the
    outer map and the values in the inner Map.
    <c:forEach var="outerMapEntry" items="${outerMap}">
    <c:out value="${outerMapEntry.key}"/>
    <c:forEach var="innerMapEntry" items="${outerMapEntry.value}" >
    <c:out value="${innerMapEntry.value}"/>
    </c:forEach>
    </c:forEach>

    See http://wiki.wendysmoak.com/cgi-bin/wiki.pl?JSTLNestedMapIterate for
    test code.

    --
    Wendy Smoak




    ---------------------------------------------------------------------
    To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
    For additional commands, e-mail: user-help@struts.apache.org
  • Jeff Beal at May 24, 2005 at 8:23 pm
    See http://struts.apache.org/faqs/struts-el.html. It includes a list
    of Struts tags whose functionality is covered by the JSTL.
    On 5/24/05, Pushkala_Iyer@dell.com wrote:

    Thanks! That worked, and is also much easier to understand.

    This is probably a newbie question: How / when does one choose between
    using JSTL / Struts Tags?
    Is there any reason to choose Struts tags over JSTL?

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

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupuser @
categoriesstruts
postedMay 23, '05 at 9:53p
activeMay 24, '05 at 8:23p
posts6
users4
websitestruts.apache.org
irc#struts

People

Translate

site design / logo © 2022 Grokbase