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 Dmitri Ilyin <dm...@gmx.net> on 2003/07/15 16:41:15 UTC

how to ask length of collection in JSTL tags

Hi,

how can i get the length(size) of the collection??
I have a collection in page scope and i'd like to check the length of this
collection.
I use <c:if test="${collection.length == 1}">
            that's it
         </c:if>
"collection.length" returns always 0. the same with "collection.size" and
"collection.itemCount"

HELP!!

thanks a lot

regards

Dmitri




---------------------------------------------------------------------
To unsubscribe, e-mail: taglibs-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: taglibs-user-help@jakarta.apache.org


RE: how to ask length of collection in JSTL tags

Posted by Mark B Starmer <ma...@markstarmer.co.uk>.
I just iterate through the collection incrementing a temp value to get
the length to solve the problem... Not too efficient I know, but at
least it works... I wouldn't use with large collections for obvious
reasons though.

Best Regards

Mark Starmer

http://www.markstarmer.co.uk

-----Original Message-----
From: Henri Yandell [mailto:bayard@generationjava.com] 
Sent: 15 July 2003 15:59
To: Tag Libraries Users List
Subject: Re: how to ask length of collection in JSTL tags



My recommendation is to use the Xephyrus Collections taglib for this. I
don't think JSTL can solve it until JSTL 1.1.

http://www.xephyrus.com/

Hen

On Tue, 15 Jul 2003, Dmitri Ilyin wrote:

> Hi,
>
> how can i get the length(size) of the collection??
> I have a collection in page scope and i'd like to check the length of 
> this collection. I use <c:if test="${collection.length == 1}">
>             that's it
>          </c:if>
> "collection.length" returns always 0. the same with "collection.size"
and
> "collection.itemCount"
>
> HELP!!
>
> thanks a lot
>
> regards
>
> Dmitri
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: taglibs-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: taglibs-user-help@jakarta.apache.org
>



---------------------------------------------------------------------
To unsubscribe, e-mail: taglibs-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: taglibs-user-help@jakarta.apache.org




---------------------------------------------------------------------
To unsubscribe, e-mail: taglibs-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: taglibs-user-help@jakarta.apache.org


Re: how to ask length of collection in JSTL tags

Posted by Eric W Hauser <eh...@indiana.edu>.
Although the bean idea is a good workaround, that may not be the most
efficient way to do this for a large application with a large of
collections. Since object created is one of the most expensive tasks in
Java, it may be more efficient to come up with a different solution than
using a bean as a wrapper.

What I've done for my project is to set the collection size as an
attribute in the request or session, depending on the scope I need.  Of 
course, I'm still creating new objects when doing this (the String for
the attribute name, etc), but it is being stored in the either the
Request or Session objects.  Since this are already created, would this 
not be more efficient? I'm not sure if it is more efficient or not
because I'm not sure of the overhead involved in creating new request or
session variables.

-------------------
Eric Hauser
ehauser@indiana.edu
(317) 679-4766


---------------------------------------------------------------------
To unsubscribe, e-mail: taglibs-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: taglibs-user-help@jakarta.apache.org


Re: how to ask length of collection in JSTL tags

Posted by Henri Yandell <ba...@generationjava.com>.
My recommendation is to use the Xephyrus Collections taglib for this. I
don't think JSTL can solve it until JSTL 1.1.

http://www.xephyrus.com/

Hen

On Tue, 15 Jul 2003, Dmitri Ilyin wrote:

> Hi,
>
> how can i get the length(size) of the collection??
> I have a collection in page scope and i'd like to check the length of this
> collection.
> I use <c:if test="${collection.length == 1}">
>             that's it
>          </c:if>
> "collection.length" returns always 0. the same with "collection.size" and
> "collection.itemCount"
>
> HELP!!
>
> thanks a lot
>
> regards
>
> Dmitri
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: taglibs-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: taglibs-user-help@jakarta.apache.org
>



---------------------------------------------------------------------
To unsubscribe, e-mail: taglibs-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: taglibs-user-help@jakarta.apache.org