tags:

views:

3591

answers:

2

I've been trying to evaluate if this array list is empty or not but none of these have even compiled:

<c:if test="${myObject.featuresList.size == 0 }">       
<c:if test="${myObject.featuresList.length == 0 }">     
<c:if test="${myObject.featuresList.size() == 0 }">     
<c:if test="${myObject.featuresList.length() == 0 }">       
<c:if test="${myObject.featuresList.empty}">        
<c:if test="${myObject.featuresList.empty()}">      
<c:if test="${myObject.featuresList.isEmpty}">

How can I evaluate if an ArrayList is empty?

+9  A: 

empty is an operator.

<c:if test="${empty myObject.featuresList}">
bobince
I dont' know what I hate more, the jstl, my lack of knowledge of it, or my damn app server that takes years to reload the most simpler jsp change. Thank bobince. I should have asked this before here. Do you happen to have a jsl reference for me?
OscarRyz
See: http://ndpsoftware.com/JSPXMLCheatSheet.html
RHSeeger
Although it is documented that the empty operator doesn't play well with Set implementation of Collections in JSTL prior to v2.0
casey
+3  A: 

There's also the function tags, a bit more flexible:

<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<c:if test="${fn:length(list) > 0}">

And here's the tag documentation.

Steve B.