There is no built-in function to verify that: you must write your own tld function, which takes a list and an element, and calls the list contains () method. eg.
//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>
Then create a class called Yourclass and add a static method that contains the above signature. I am sure that the implementation of this method is pretty clear:
package com;
Then you can use it in your jsp:
<%@ taglib uri="/WEB-INF/custom-functions.tld" prefix="fn" %> <c:if test="${ fn:contains( mylist, myValue ) }">style='display:none;'</c:if>
The tag can be used from any JSP on the site.
edit: more information about the tld file - more info here
Chii Sep 29 '09 at 1:45 2009-09-29 01:45
source share