You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Kevin Galligan <kg...@gmail.com> on 2006/10/03 20:58:16 UTC
forEach accesses 'items' collection multiple times
I'm using the 'forEach' tag in a page. When I ran a debugger against
my code, it looks like the forEach is grabbing the collection in the
'items' attribute each time it runs through the loop. I'd think it
would only do this once. Here's the code...
<c:forEach items="#{sharedPortalsSpecialtySponsorProgramMixer.sponsorProducts}"
var="sponsorProduct">
<tr>
<td style="border-bottom: 0px">
<h:outputText value="#{sponsorProduct.title}"/>
</td>
</tr>
</c:forEach>
Each row in 'sponsorProducts' causes a call to grab the whole list.
If I take the 'h:outputText' out of the cell and just dump out some
regular text (ie. don't access the 'sponsorProduct'), it only grabs
the list once.
Facelets version '1.1.11'. I can make this "work" by caching the list
rather than having it hit the db each time, but it seems really odd.
Like I have something configured wrong.
Thanks in advance,
-Kevin
Re: forEach accesses 'items' collection multiple times
Posted by Kevin Galligan <kg...@gmail.com>.
Once I swapped to ui:repeat, all the problems went away.
I saw the thing about not using forEach in the docs after I sent this.
Still, thought it was odd that it grabs the collection on each run.
Thanks,
-Kevin
On 10/3/06, Jeff Bischoff <jb...@klkurz.com> wrote:
> Kevin,
>
> There are lots of issues in JSF 1.1 with collection tags like c:forEach.
> To avoid running into these, I use forEach sparingly in my app. When I
> do use it, I also use c:out rather than h:outputText. See [1] for some info.
>
> [1] http://java.sun.com/developer/technicalArticles/J2EE/jsp_21/
>
> Regards,
>
> Jeff Bischoff
> Kenneth L Kurz & Associates, Inc.
>
> Kevin Galligan wrote:
> > I'm using the 'forEach' tag in a page. When I ran a debugger against
> > my code, it looks like the forEach is grabbing the collection in the
> > 'items' attribute each time it runs through the loop. I'd think it
> > would only do this once. Here's the code...
> >
> > <c:forEach
> > items="#{sharedPortalsSpecialtySponsorProgramMixer.sponsorProducts}"
> > var="sponsorProduct">
> > <tr>
> > <td style="border-bottom: 0px">
> > <h:outputText value="#{sponsorProduct.title}"/>
> > </td>
> > </tr>
> > </c:forEach>
> >
> > Each row in 'sponsorProducts' causes a call to grab the whole list.
> > If I take the 'h:outputText' out of the cell and just dump out some
> > regular text (ie. don't access the 'sponsorProduct'), it only grabs
> > the list once.
> >
> > Facelets version '1.1.11'. I can make this "work" by caching the list
> > rather than having it hit the db each time, but it seems really odd.
> > Like I have something configured wrong.
> >
> > Thanks in advance,
> > -Kevin
> >
> >
> >
>
>
>
Re: forEach accesses 'items' collection multiple times
Posted by Jeff Bischoff <jb...@klkurz.com>.
Kevin,
There are lots of issues in JSF 1.1 with collection tags like c:forEach.
To avoid running into these, I use forEach sparingly in my app. When I
do use it, I also use c:out rather than h:outputText. See [1] for some info.
[1] http://java.sun.com/developer/technicalArticles/J2EE/jsp_21/
Regards,
Jeff Bischoff
Kenneth L Kurz & Associates, Inc.
Kevin Galligan wrote:
> I'm using the 'forEach' tag in a page. When I ran a debugger against
> my code, it looks like the forEach is grabbing the collection in the
> 'items' attribute each time it runs through the loop. I'd think it
> would only do this once. Here's the code...
>
> <c:forEach
> items="#{sharedPortalsSpecialtySponsorProgramMixer.sponsorProducts}"
> var="sponsorProduct">
> <tr>
> <td style="border-bottom: 0px">
> <h:outputText value="#{sponsorProduct.title}"/>
> </td>
> </tr>
> </c:forEach>
>
> Each row in 'sponsorProducts' causes a call to grab the whole list.
> If I take the 'h:outputText' out of the cell and just dump out some
> regular text (ie. don't access the 'sponsorProduct'), it only grabs
> the list once.
>
> Facelets version '1.1.11'. I can make this "work" by caching the list
> rather than having it hit the db each time, but it seems really odd.
> Like I have something configured wrong.
>
> Thanks in advance,
> -Kevin
>
>
>