Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Evaluate if list is empty JSTL

Tags:

java

jsp

jstl

People also ask

How do I check if a list is empty in JSTL?

The first way is to use the JSTL tag and empty operator to check if an ArrayList is empty and the second way is to use the JSTL function, fn: length() instead of the empty operator as shown in our example.

Is empty in JSTL?

Summarized: empty doesn't work on Set when using the ancient JSTL 1.0. You'd need to upgrade to JSTL 1.1 (which is from 2003 already).

How check list is empty or not in JSP?

using empty is ok, but on the list ${empty list} which returns true, both if list is empty or null.

How to check list size in jsp page?

Is it possible at jsp to get the list size using jstl? or shall i use <% %> to get the size like jsp 1.0? If you want to avoid sciptlets, a little wrapper around your list, with a getSize() method could do the trick. Or you could even put the list size in a request atribute.


empty is an operator:

The empty operator is a prefix operation that can be used to determine whether a value is null or empty.

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

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.