Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JSTL printing issue

 
Sripathi Krishnamurthy
Ranch Hand
Posts: 232
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have this problem..

In a JAVA class I have the below code


In a JSP, I have written a JSTL which is written this way,


So basically what I have is, a Hashmap which has String as a key and an ArrayList object as a value.
When I try to run this, I get the error cannot run forEach for "items".
What part of code am I not writing correctly? Please help.
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hai
culprit:
request.setAttribute("param",map);

change your name from param to param1 or something else..because param is one of the implicit object in EL...more over for:Each items should be collection or array

Hope THis Helps
 
Sripathi Krishnamurthy
Ranch Hand
Posts: 232
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by seetharaman venkatasamy:
hai
culprit:
request.setAttribute("param",map);

change your name from param to param1 or something else..because param is one of the implicit object in EL...more over for:Each items should be collection or array

Hope THis Helps


The one I have given above is just an example. I havent used param as I have given there. The variable names that I am using in my application is entirely different. For this example, you can assume it as "param1" as you have indicated.
Thanks
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
insteadof <cut value="${users}"/> you just use

${uesrs}...and let me know
 
Steve Luke
Bartender
Posts: 4181
21
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you iterate over a map you are iterating over the entry set, not the map directly. This means that each value returned by the outer loop is a MapEntry, not an ArrayList. The MapEntry would have a method getValue() which would return the ArrayList to use for the inner loop. Example:
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks luke
 
Sripathi Krishnamurthy
Ranch Hand
Posts: 232
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Steve Luke:
When you iterate over a map you are iterating over the entry set, not the map directly. This means that each value returned by the outer loop is a MapEntry, not an ArrayList. The MapEntry would have a method getValue() which would return the ArrayList to use for the inner loop. Example:


Thank you very much. It is working fine now.
Regards
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic