Shawn,
Yes, I agree the best work around for now is to provide the getSize()
accessor to your collection. Unfortunately I can't provide the getSize() in
this case because I'm iterating a native array and don't have a wrapper.
But I did realize that to find out if there is exactly 1, all I really need
to pre-iterate is the first two elements using the end attribute. This
eases the pain of having to iterate the entire collection twice.
<c:forEach varStatus="s" items="${dataSources}" end="1">
<c:set var="size" value="${s.count}"/>
</c:forEach>
<c:choose>
<c:when test="${size == 1}">
.. Do what needs to be done when there is exactly one element in the
array
</c:when>
<c:otherwise>
.. Do what needs to be done when there are more than one
</c:otherwise>
</c:choose>
-----Original Message-----
From: Shawn Bayern [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, April 24, 2002 4:37 PM
To: Tag Libraries Users List
Subject: RE: [standard] query tag exception when no session
On Wed, 24 Apr 2002, Halvorson, Loren wrote:
> The one thing I really would have liked was the ability to test the
> size of a collection before I iterate it. (in my case I needed to
> know when there is exactly 1 item) I know there was a discussion on
> this a little while ago and saw your workaround to pre-iterate it, but
> it's not a practical solution for large collections. So while I had
> your ear, I just wanted get my vote in to add some way to do it.
> Although I'm sure it's too late.
It's indeed too late for JSTL 1.0, though we realize it's important and will
probably address it in JSTL 1.1/JSP 1.3. The best workaround, when you're a
Java programmer, is to provide all data the page authors will need yourself;
e.g.,
public class MyData {
Collection collection = ...;
public Collection getCollection() { return collection; }
public int getSize() { return collection.size(); }
// accessors useful data other than size
}
Glad to hear you're enjoying JSTL, though! Thanks for the note.
--
Shawn Bayern
"JSP Standard Tag Library" http://www.jstlbook.com
(coming this summer from Manning Publications)
--
To unsubscribe, e-mail:
<mailto:[EMAIL PROTECTED]>
For additional commands, e-mail:
<mailto:[EMAIL PROTECTED]>
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>