You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Michael Bowman <mi...@comcast.net> on 2002/09/26 21:06:01 UTC

Please help with iteration problem

I am trying to nest iterate tags. I've tried <logic:iterate> <nested:iterate> and <c:forEach> without success. Here's what I want to do.

<logic:iterate name="routes" id="route" type="RouteBean">
   write stuff about the route.
   <logic:iterate name="route" property="segments" id="segment" type="SegmentBean">
      write stuff about the segment
   </logic:iterate>
</logic:iterate>

"routes" points to a java.util.List of RouteBeans. Each RouteBean has a method, getSegments() that returns a java.util.List of SegmentBeans.

I've looked at the documents and examples for the nested tag, but I don't see anything about this type of nesting. I don't have a "monkey" with a single "bunch" of bananas, instead I simply have a java.util.List of bunches, each of which has a java.util.List of bananas.

I'd really appreciate any help ya'll can give me. I'm up for using any tag type (struts-logic, struts-nested, or JSTL). I'd just rather not fall back on scriptlets if I can help it.

Thanks,
Michael Bowman

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Please help with iteration problem

Posted by Eddie Bush <ek...@swbell.net>.
I know David has committed it -- I got a ton of messages on it when he 
did (subscribe to the dev list and you too can keep up with things like 
this!).  Do a checkout from CVS.  If it's not there ... well, it's got 
to be.  Let me update my cvs and see.  Ok, I'm wrong.  It's been added 
but not commited apparantly.

To quote David:

>The library isn't in the form of a patch, it's an
>independent library, and the distribution is an attachment on the enhancement
>request (#12365)
>
http://issues.apache.org/bugzilla <--------- go here - enter ^ that ID. 
 Submit, download as struts-el.tgz (it will want to give it a .cgi filename)

That should have you set :-)

If you get stuck, just hollar.

Michael Bowman wrote:

>One further complication: I found that nested <logic:iterate> tags work on Tomcat 4.0.3, but not on Tomcat 4.1.10. Thats kind of weird.
>
>I don't see the struts-el tags listed on the Struts Resources/Contributor Taglibs page. Can you tell me where to find them? Thanks. 
>
>On Thu, 26 Sep 2002 17:48:30 -0500
>

-- 
Eddie Bush




--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Please help with iteration problem

Posted by Michael Bowman <mi...@comcast.net>.
Correction, it seems that the version of Tomcat doesn't matter after all. A JSP with nested <logic:iterate> tags worked before, but not now. Maybe it was with an earlier version of Struts. Does anyone know if the behavior of <logic:iterate> changed with respect to nesting the tags between Struts 1.0 and Struts 1.1b?

On Thu, 26 Sep 2002 19:02:19 -0400
Michael Bowman <mi...@comcast.net> wrote:

> One further complication: I found that nested <logic:iterate> tags work on Tomcat 4.0.3, but not on Tomcat 4.1.10. Thats kind of weird.
> 
> I don't see the struts-el tags listed on the Struts Resources/Contributor Taglibs page. Can you tell me where to find them? Thanks. 
> 
> On Thu, 26 Sep 2002 17:48:30 -0500
> Eddie Bush <ek...@swbell.net> wrote:
> 
> > Find out about, download, install, and use the new contributed taglib 
> > struts-el.
> > 
> > Michael Bowman wrote:
> > 
> > >Thanks for the reply. I'm going to try it. As a matter of fact, I do have IDs that I'm using for the segments and objects contained within the segments. I want to use <html:link> tags within the loops to build links displaying various information about these objects.
> > >
> > >Do you know if I can use Struts tags inside of the JSTL tags? If the JSTL tags just put beans in some scope, will the Struts tags know any difference?
> > >
> > >
> > >On Thu, 26 Sep 2002 15:20:45 -0500
> > >Eddie Bush <ek...@swbell.net> wrote:
> > >
> > >><c:set var="routes" value="${pageScope['routesKey']}"/>
> > >>- or -
> > >><c:set var="routes" value="${requestScope['routesKey']}"/>
> > >>- or -
> > >><c:set var="routes" value="${sessionScope['routesKey']}"/>
> > >>- or -
> > >><c:set var="routes" value="${applicationScope['routesKey']}"/>
> > >>
> > >
> > >Do I need the above if I put the java.util.List on the request object in my Struts Action class prior to forwarding to the JSP?
> > >
> > No.  You could reference it as ${requestScope['key']} I believe.  In 
> > fact ... *ponder* ... you could possible access it by ${key}.  I think 
> > that may work too.  I always go through the scope ...
> > 
> > -- 
> > Eddie Bush
> > 
> > 
> > 
> > 
> > --
> > To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> > For additional commands, e-mail: <ma...@jakarta.apache.org>
> > 
> 
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
> 

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Please help with iteration problem

Posted by Michael Bowman <mi...@comcast.net>.
One further complication: I found that nested <logic:iterate> tags work on Tomcat 4.0.3, but not on Tomcat 4.1.10. Thats kind of weird.

I don't see the struts-el tags listed on the Struts Resources/Contributor Taglibs page. Can you tell me where to find them? Thanks. 

On Thu, 26 Sep 2002 17:48:30 -0500
Eddie Bush <ek...@swbell.net> wrote:

> Find out about, download, install, and use the new contributed taglib 
> struts-el.
> 
> Michael Bowman wrote:
> 
> >Thanks for the reply. I'm going to try it. As a matter of fact, I do have IDs that I'm using for the segments and objects contained within the segments. I want to use <html:link> tags within the loops to build links displaying various information about these objects.
> >
> >Do you know if I can use Struts tags inside of the JSTL tags? If the JSTL tags just put beans in some scope, will the Struts tags know any difference?
> >
> >
> >On Thu, 26 Sep 2002 15:20:45 -0500
> >Eddie Bush <ek...@swbell.net> wrote:
> >
> >><c:set var="routes" value="${pageScope['routesKey']}"/>
> >>- or -
> >><c:set var="routes" value="${requestScope['routesKey']}"/>
> >>- or -
> >><c:set var="routes" value="${sessionScope['routesKey']}"/>
> >>- or -
> >><c:set var="routes" value="${applicationScope['routesKey']}"/>
> >>
> >
> >Do I need the above if I put the java.util.List on the request object in my Struts Action class prior to forwarding to the JSP?
> >
> No.  You could reference it as ${requestScope['key']} I believe.  In 
> fact ... *ponder* ... you could possible access it by ${key}.  I think 
> that may work too.  I always go through the scope ...
> 
> -- 
> Eddie Bush
> 
> 
> 
> 
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
> 

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Please help with iteration problem

Posted by Eddie Bush <ek...@swbell.net>.
Find out about, download, install, and use the new contributed taglib 
struts-el.

Michael Bowman wrote:

>Thanks for the reply. I'm going to try it. As a matter of fact, I do have IDs that I'm using for the segments and objects contained within the segments. I want to use <html:link> tags within the loops to build links displaying various information about these objects.
>
>Do you know if I can use Struts tags inside of the JSTL tags? If the JSTL tags just put beans in some scope, will the Struts tags know any difference?
>
>
>On Thu, 26 Sep 2002 15:20:45 -0500
>Eddie Bush <ek...@swbell.net> wrote:
>
>><c:set var="routes" value="${pageScope['routesKey']}"/>
>>- or -
>><c:set var="routes" value="${requestScope['routesKey']}"/>
>>- or -
>><c:set var="routes" value="${sessionScope['routesKey']}"/>
>>- or -
>><c:set var="routes" value="${applicationScope['routesKey']}"/>
>>
>
>Do I need the above if I put the java.util.List on the request object in my Struts Action class prior to forwarding to the JSP?
>
No.  You could reference it as ${requestScope['key']} I believe.  In 
fact ... *ponder* ... you could possible access it by ${key}.  I think 
that may work too.  I always go through the scope ...

-- 
Eddie Bush




--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Please help with iteration problem

Posted by Michael Bowman <mi...@comcast.net>.
Thanks for the reply. I'm going to try it. As a matter of fact, I do have IDs that I'm using for the segments and objects contained within the segments. I want to use <html:link> tags within the loops to build links displaying various information about these objects.

Do you know if I can use Struts tags inside of the JSTL tags? If the JSTL tags just put beans in some scope, will the Struts tags know any difference?


On Thu, 26 Sep 2002 15:20:45 -0500
Eddie Bush <ek...@swbell.net> wrote:

> <c:set var="routes" value="${pageScope['routesKey']}"/>
> - or -
> <c:set var="routes" value="${requestScope['routesKey']}"/>
> - or -
> <c:set var="routes" value="${sessionScope['routesKey']}"/>
> - or -
> <c:set var="routes" value="${applicationScope['routesKey']}"/>

Do I need the above if I put the java.util.List on the request object in my Struts Action class prior to forwarding to the JSP?

> 
> <c:forEach values="${routes}" var="route">
>     <!-- Iterate over routes -->
>     Route ID: <c:out value="${route.id}"/><br>
>     <c:forEach values="${route.segments}" var="segment">
>         <!-- Iterate over segments -->
>         Segment ID: <c:out value="${route.id}"/><br>
>     </c:forEach>
> </c:forEach>
> 
> (I don't know if your routes/segments have an id property - it's just an 
> example)
> 
> I'm reasonably certain this should work.  I use basically the same 
> construct to go over an ArrayList (exposed as a Collection) and it's 
> nested ArrayList (again, exposed as a Collection).
> 
> Michael Bowman wrote:
> 
> >I am trying to nest iterate tags. I've tried <logic:iterate> <nested:iterate> and <c:forEach> without success. Here's what I want to do.
> >
> ><logic:iterate name="routes" id="route" type="RouteBean">
> >   write stuff about the route.
> >   <logic:iterate name="route" property="segments" id="segment" type="SegmentBean">
> >      write stuff about the segment
> >   </logic:iterate>
> ></logic:iterate>
> >
> >"routes" points to a java.util.List of RouteBeans. Each RouteBean has a method, getSegments() that returns a java.util.List of SegmentBeans.
> >
> >I've looked at the documents and examples for the nested tag, but I don't see anything about this type of nesting. I don't have a "monkey" with a single "bunch" of bananas, instead I simply have a java.util.List of bunches, each of which has a java.util.List of bananas.
> >
> >I'd really appreciate any help ya'll can give me. I'm up for using any tag type (struts-logic, struts-nested, or JSTL). I'd just rather not fall back on scriptlets if I can help it.
> >
> >Thanks,
> >Michael Bowman
> >
> 
> -- 
> Eddie Bush
> 
> 
> 
> 
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
> 

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Please help with iteration problem

Posted by Eddie Bush <ek...@swbell.net>.
<c:set var="routes" value="${pageScope['routesKey']}"/>
- or -
<c:set var="routes" value="${requestScope['routesKey']}"/>
- or -
<c:set var="routes" value="${sessionScope['routesKey']}"/>
- or -
<c:set var="routes" value="${applicationScope['routesKey']}"/>

<c:forEach values="${routes}" var="route">
    <!-- Iterate over routes -->
    Route ID: <c:out value="${route.id}"/><br>
    <c:forEach values="${route.segments}" var="segment">
        <!-- Iterate over segments -->
        Segment ID: <c:out value="${route.id}"/><br>
    </c:forEach>
</c:forEach>

(I don't know if your routes/segments have an id property - it's just an 
example)

I'm reasonably certain this should work.  I use basically the same 
construct to go over an ArrayList (exposed as a Collection) and it's 
nested ArrayList (again, exposed as a Collection).

Michael Bowman wrote:

>I am trying to nest iterate tags. I've tried <logic:iterate> <nested:iterate> and <c:forEach> without success. Here's what I want to do.
>
><logic:iterate name="routes" id="route" type="RouteBean">
>   write stuff about the route.
>   <logic:iterate name="route" property="segments" id="segment" type="SegmentBean">
>      write stuff about the segment
>   </logic:iterate>
></logic:iterate>
>
>"routes" points to a java.util.List of RouteBeans. Each RouteBean has a method, getSegments() that returns a java.util.List of SegmentBeans.
>
>I've looked at the documents and examples for the nested tag, but I don't see anything about this type of nesting. I don't have a "monkey" with a single "bunch" of bananas, instead I simply have a java.util.List of bunches, each of which has a java.util.List of bananas.
>
>I'd really appreciate any help ya'll can give me. I'm up for using any tag type (struts-logic, struts-nested, or JSTL). I'd just rather not fall back on scriptlets if I can help it.
>
>Thanks,
>Michael Bowman
>

-- 
Eddie Bush




--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>