File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes Passing java collection object using EL to a custom tag Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » JSP
Reply Bookmark "Passing java collection object using EL to a custom tag" Watch "Passing java collection object using EL to a custom tag" New topic
Author

Passing java collection object using EL to a custom tag

Zakas Banda
Greenhorn

Joined: Dec 29, 2008
Posts: 5
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

Joined: Jan 10, 2002
Posts: 56185
    
  13

You should be receiving the Map directly. No casting should be necessary. Is your tag implemented to expect a String or a Map?


[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
Stefan Evans
Bartender

Joined: Jul 06, 2005
Posts: 1004
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

Joined: Dec 29, 2008
Posts: 5
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

Joined: Jan 10, 2002
Posts: 56185
    
  13

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

Joined: Dec 29, 2008
Posts: 5
Hi Bear

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

-Thanks
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Passing java collection object using EL to a custom tag
 
Similar Threads
body-content as scriptless
JSP EL not working
SchemaLocation Error In Eclipse IDE
Problems making Struts/JSTL 1.2 site work with JSTL 2.0