Wednesday, July 30, 2008

Custom tags: passing in maps or other datatypes that arent strings

problem:
I needed to pass a hashmap into a custom tag. This hashmap was to be created on the jsp page using jstl, and then passed into the tag as an attribute.
For some reason i was not able to find the solution with just one google query.

solution:

1. first, to create a hashmap on the jsp using jstl and add some stuff to it:


2. next, add another attribute to your tag in the tld file:


3. finally, pass the hashmap into your tag .. <tag someName="${something}" /> and make sure that the setter in the tag takes in a Map

1 comment:

  1. Just what I needed. And I found it with one Google search, because of you! Thanks man.

    ReplyDelete