You are viewing a plain text version of this content. The canonical link for it is here.
Posted to taglibs-user@tomcat.apache.org by Liam <st...@hotmail.com> on 2002/05/14 17:21:21 UTC
using forEach with ArrayList? - bug??
Hi
We have been trying unsuccessfully to iterate over an ArrayList object using the JSTL tag forEach.
We think it could be a bug, but then we may be using it wrong :-). Although we have successfully managed to use forEach for iterating over Collections (which are in a bean).
this is out code snippet
<%
ArrayList classifiers = Classifier.DA.getAll();
%>
<c:forEach var="classifier" items="$classifiers" varStatus="status" >
<option>
<c:out value="${classifier.name()}"/>
</option>
</c:forEach>
Any help/advice on this is much appreciated!!!
Thanks
Liam.
com21.com
Temp. contractor.
Re: using forEach with ArrayList? - bug??
Posted by Paul DuBois <pa...@snake.net>.
At 16:21 +0100 5/14/02, Liam wrote:
>Hi
>
>We have been trying unsuccessfully to iterate over an ArrayList
>object using the JSTL tag forEach.
>
>We think it could be a bug, but then we may be using it wrong :-).
>Although we have successfully managed to use forEach for iterating
>over Collections (which are in a bean).
>
>this is out code snippet
>
> <%
> ArrayList classifiers = Classifier.DA.getAll();
request.setAttribute ("classifiers", classifiers);
I dunno if that's really the "right" way to do it, but it works for me.
I'd be glad to know if there's an approved way, if this isn't it.
> %>
> <c:forEach var="classifier" items="$classifiers"
>varStatus="status" >
> <option>
> <c:out value="${classifier.name()}"/>
> </option>
> </c:forEach>
>
>Any help/advice on this is much appreciated!!!
>
>Thanks
>
>Liam.
>com21.com
>Temp. contractor.
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: using forEach with ArrayList? - bug??
Posted by Shawn Bayern <ba...@essentially.net>.
On Tue, 14 May 2002, Liam wrote:
> this is out code snippet
>
> <%
> ArrayList classifiers = Classifier.DA.getAll();
> %>
> <c:forEach var="classifier" items="$classifiers" varStatus="status" >
Two problems:
- The syntax for expressions is now ${expr}, not $expr. You need to
write ${classifiers}.
- Simply declaring a scripting variable (through your "ArrayList
classifiers" declaration) isn't enough to make the data accessible
to a JSP tag. If you create it manually in a scriptlet, you'll need
to add it to a scope using pageContext.setAttribute().
--
Shawn Bayern
"JSP Standard Tag Library" http://www.jstlbook.com
(coming this summer from Manning Publications)
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>