• Post Reply Bookmark Topic Watch Topic
  • New Topic

Passing java collection object using EL to a custom tag

 
Zakas Banda
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All

I need your help.

We were using JSTL 1.0 and I had written a custom tag that takes a map and works with it ... the way it was used is as follows...

<abc:myTag data="${data.statusMap}"/>

Recently we gave ourselves a big boost and upgraded to tomcat 6.0 and JSTL 1.2.

Now, my tag receives the map in its toString form. that is {key1:value1, key2:value2}, which causes class cast exception (String to map).

Here is a snippet from my tld

<taglib xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-jsptaglibrary_2_1.xsd"
version="2.1">

<tag>
<name>MyTag</name>
<tag-class>com.MyTagClass</tag-class>
<body-content>empty</body-content>
<attribute>
<name>data</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>
</taglib>
=====

Any help or pointers will be appreciated.

Thanks
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65530
108
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should be receiving the Map directly. No casting should be necessary. Is your tag implemented to expect a String or a Map?
 
Stefan Evans
Bartender
Posts: 1822
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well if you wrote your tag for JSTL1.0, then the attribute passed in would be expected as String (the EL expression), and somewhere in the depths of your code you will be evaluating that EL expression.

From JSP2.0, the container evaluates the EL expression - meaning it is actually passing you the Map - not the expression to evaluate.
So you will need to revisit your tag, change the tld so that it accepts a Map, and remove the bit about EL evaluation in your tag implementation.


 
Zakas Banda
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stefan

Your comment about "evaluation not required" does make sense. However could you please explain what kind of changes required in tld?

Thanks
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65530
108
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you declared the type of your attribute in the TLD as a String it needs to be changed to a Map. If you left it untypes, no changes are probably necessary.
 
Zakas Banda
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Bear

As I note in my original post, there is no type defined for the attribute.

-Thanks
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!