• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JSTL List count

 
Atul Samnerkar
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I can get the list count using <c:forEach> as follows,
<c:forEach items="${mylist}" var="km" varStatus="cnt">
List Count = ${cnt.count}
</c:forEach>
Is it possible that i can get this list count directly in the <c:if> test condition without iterating thru <c:forEach>

something like <c:if test="${mylist.count gt 0}"> No data found.. </c:if>

Appreciate your response on this.

Thanks & Regards,
Atul Samnerkar
 
Michael Ku
Ranch Hand
Posts: 510
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use the JSTL 'empty' operator to see if the collection is empty
 
Roland Benedek
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I think:

Will work just fine.

On second thought, this doesnt work its not getSize();

[ September 09, 2008: Message edited by: Anton Gerdessen ]
 
Charles Lyons
Author
Ranch Hand
Posts: 836
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The 'empty' operator is your best bet for comparing to 0. If you really want to get the size however, the JSTL EL function fn:length is your friend (e.g. see JSTL Functions).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic