This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
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

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: 1517
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

I agree. Here's the link:
subject: Passing a hashmap to a tag file
It's not a secret anymore!