2009-09-23 25 views
111

He estado tratando de evaluar si esta lista matriz está vacía o no, pero ninguno de ellos incluso han compilado:Evaluar si la lista está vacía 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}"> 

¿Cómo puedo evaluar si un ArrayList está vacía?

Respuesta

221

empty es un operador.

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

No sé qué odio más, el jstl, mi falta de conocimiento o mi maldito servidor de aplicaciones que tarda años en volver a cargar el cambio de jsp más simple. Gracias bobince. Debería haber preguntado esto antes aquí. ¿Tiene una referencia jsl para mí? – OscarRyz

+15

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

+2

Aunque está documentado que el operador vacío no funciona bien con Establecer implementación de colecciones en JSTL antes de v2.0 – casey

62

Hay también las etiquetas de función, un poco más flexible:

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

Y here's la documentación etiqueta.

Cuestiones relacionadas