Monday, April 16, 2012

Evaluate if list is empty JSTL


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?


Source: Tips4all

2 comments:

  1. empty is an operator.

    <c:if test="${empty myObject.featuresList}">

    ReplyDelete
  2. 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.

    ReplyDelete