struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dave Newton <>
Subject [OT: JSTL] Re: <c:forEach> for an object that extends ArrayList in Application **and** Session
Date Wed, 13 Apr 2005 20:00:39 GMT
David Johnson wrote:

>that makes sense, but the individual portfolios (the members of the
>PortfolioBeanCollection) dont really have a name, I just looped
>through my result set doing
>PortfolioBeanCollection PBC=new PortfolioBeanCollection ();
>while (result.hasnext){
> pbc.add (new PortfolioBean(resultSet.getString("namefield")));
>so I really just used the PortfolioBeanCollection as if it were a
>garden variety ArrayList.... does your comment still apply?
Of course--you have to tell the <c:out...> tag a) what bean to get the 
property from and b) what property to display. When you say <c:forEach 
items="${userPortfolios}"...> you are telling c:forEach what collection 
to use for the iteration. When you say <c:forEach var="portfolio"...> 
you are creating a variable you can use in other JSTL tags--in essence 
naming each portfolio bean "portfolio" for the purposes of JSTL.

But you still have to tell <c:out...> what bean and what property, 
otherwise how would it know what to print? When you just say <c:out 
value="${portfolioName}"/> it's looking for an application, session, 
request, or page scoped attribute named "portfolioName". Without the 
prepended "portfolio" it doesn't know that the property "portfolioName" 
is associated with a bean created through the c:forEach iterator.

I'd recommend checking out some very basic JSTL docs to get a feel for 
how JSTL works:


(Wouldn't it have been quicker to just but the property name in your 
code and see if it worked?)

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message