Sunday, December 11, 2005

How to Pass a HashMap or Other Type into a JSP 2.0 tag file

First, lets assume your HashMap has the name "myHashMap"

Your call to the tag file could look like this:


<mytaglibrary:mytag map="${myHashMap}">


For me, the EL kept trying to change the hashmap to a string inside the .tag file. So I had to do the following at the top of the .tag file:

<%@ tag import="java.util.HashMap"%>
<%@ attribute name="map" required="true" type="java.util.HashMap"%>

Then I could use the map as usual:

The value of map.keyName is ${map.keyName}

No comments:

Labels

Blog Archive

Contributors