non esiste una funzionalità integrata per verificare che - ciò che si farebbe è scrivere la propria funzione tld che prende una lista e un elemento e chiama il metodo contains() dell'elenco. per esempio.
//in your own WEB-INF/custom-functions.tld file add this
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE taglib
PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN"
"http://java.sun.com/dtd/web-jsptaglibrary_1_2.dtd">
<taglib
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd"
version="2.0"
>
<tlib-version>1.0</tlib-version>
<function>
<name>contains</name>
<function-class>com.Yourclass</function-class>
<function-signature>boolean contains(java.util.List,java.lang.Object)
</function-signature>
</function>
</taglib>
Quindi creare una classe denominata Yourclass e aggiungere un metodo statico chiamato contiene con la firma precedente. Sono sicuro che l'attuazione di tale metodo è piuttosto auto esplicativo:
package com; // just to illustrate how to represent the package in the tld
public class Yourclass {
public static boolean contains(List list, Object o) {
return list.contains(o);
}
}
Quindi è possibile utilizzare nel vostro jsp:
<%@ taglib uri="/WEB-INF/custom-functions.tld" prefix="fn" %>
<c:if test="${ fn:contains(mylist, myValue) }">style='display:none;'</c:if>
Il tag può essere utilizzato da qualsiasi JSP nel sito.
edit: maggiori informazioni riguardo il file tld - more info here
Si noti che la sintassi data lavora come intented dal EL 2.2 (che è portato come parte di Servlet 3.0/JSP 2.2 che è stato rilasciato dic 2009). – BalusC
possibile duplicato di [Set ed elenchi JSTL - verifica se l'elemento esiste in un set] (http://stackoverflow.com/questions/1076679/jstl-sets-and-lists-checking-if-item-exists-in-a -set) –