JSTL - number of elements in list

C

Christine Mayer

Hi, using a tag library (preferably JSTL), I would like to print of
something, in case my list has a certain amount of elements -

I tried <c:if test="{myList.size > 10 }">, however this doesn't work,
as this results in myList.getSize() but the method's name is just
size().

Any idea how this can be done?

Thanks,

Christine
 
T

Tobi

Hi, using a tag library (preferably JSTL), I would like to print of
something, in case my list has a certain amount of elements -

I tried <c:if test="{myList.size > 10 }">, however this doesn't work,
as this results in myList.getSize() but the method's name is just
size().

Any idea how this can be done?

Thanks,

Christine

at http://java.sun.com/j2ee/1.4/docs/tutorial/doc/JSTL8.html I found:

Although the java.util.Collection interface defines a size method, it
does not conform to the JavaBeans component design pattern for
properties and so cannot be accessed via the JSP expression language.
The length function can be applied to any collection supported by the
c:forEach and returns the length of the collection. When applied to a
String, it returns the number of characters in the string.

HTH!

Tobi
 
T

Tobi

athttp://java.sun.com/j2ee/1.4/docs/tutorial/doc/JSTL8.htmlI found:

Although the java.util.Collection interface defines a size method, it
does not conform to the JavaBeans component design pattern for
properties and so cannot be accessed via the JSP expression language.
The length function can be applied to any collection supported by the
c:forEach and returns the length of the collection. When applied to a
String, it returns the number of characters in the string.

HTH!

Tobi

Also found:

<c:if test="${fn:length(myList) > 0}">

http://forum.java.sun.com/thread.jspa?threadID=511513&messageID=2431122
 
D

Daniel Pitts

Christine said:
Hi, using a tag library (preferably JSTL), I would like to print of
something, in case my list has a certain amount of elements -

I tried <c:if test="{myList.size > 10 }">, however this doesn't work,
as this results in myList.getSize() but the method's name is just
size().

Any idea how this can be done?
<c:if test="${fn:length(myList) > 10}">

You'll need to import the function taglib, but it is part of the JSTL.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top