File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSP and the fly likes Passing a hashmap to a tag file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Passing a hashmap to a tag file" Watch "Passing a hashmap to a tag file" New topic

Passing a hashmap to a tag file

Nauman Hasan
Ranch Hand

Joined: Jul 27, 2005
Posts: 34
Hi folks,

I am using Tag Files with JSP and ran into a puzzling issue. Just as background I am using JDK 1.6 and Apache Tomcat 6.0.33. In short the same code in tag seems to be causing a exception. So what I am wondering is if there is translation occuring in between the JSP and Tag file (even with tag attribute is marked as dynamic). Thanks for your help!

In the main JSP page I have the following (snippets)

The output is

In the tag file I have following code snippets

If don't put in the last forEach then I get

Otherwise there is an exception

Any help would be appreciated.

Stefan Evans

Joined: Jul 06, 2005
Posts: 1016
You are missing a vital element in the declaration of the attribute in your tag file:

Unless you specify the type, it assumes the attribute you are declaring is a String.
Doing a <c:forEach> over a String is valid (assumes it is a comma separated list of strings, and so returns each element as a String)
Hence why the first loop 'works' but the second one failed.
Nauman Hasan
Ranch Hand

Joined: Jul 27, 2005
Posts: 34
You sir and fabulous!

Thanks it works now

It is sorta covered in the JavaRanch Style Guide.
subject: Passing a hashmap to a tag file
Similar Threads
Custom tag library 101 question
How to Set HashMap in request attribute using JSTL Tag
Unable to access array values using EL
Recursive JSP function