2009-09-23 10 views
111

Ho cercato di valutare se questa lista di array è vuoto o no, ma nessuno di questi hanno addirittura compilato:Valutare se l'elenco è vuoto JSTL

<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}"> 

Come posso valutare se un ArrayList è vuoto?

risposta

221

empty è un operatore.

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

Non so cosa odio di più, il jstl, la mia mancanza di conoscenza di esso, o il mio dannato app server che impiega anni per ricaricare il più semplice cambiamento jsp. Grazie a Bobince. Avrei dovuto chiederlo prima qui. Ti capita di avere un riferimento jsl per me? – OscarRyz

+15

Vedere: http://ndpsoftware.com/JSPXMLCheatSheet.html – RHSeeger

+2

Sebbene sia documentato che l'operatore vuoto non giochi bene con Imposta implementazione di raccolte in JSTL prima della versione 2.0 – casey

62

C'è anche i tag di funzione, un po 'più flessibile:

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

E here's la documentazione tag.