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.
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).
using empty is ok, but on the list ${empty list} which returns true, both if list is empty or null.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With