This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes JSP and the fly likes JSTL's EL.  Problem iterating over arraylist Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "JSTL Watch "JSTL New topic
Author

JSTL's EL. Problem iterating over arraylist

starrman777
Greenhorn

Joined: Mar 23, 2005
Posts: 6
I am passing a ViewBean into a JSP page.
The ViewBean Contains a Map
The Key for the Map is a String
The Value for the Map is an ArrayList of Car objects

The viewBean is accessed using useBean.
<jsp:useBean id="viewBean"
class="com.whatever.MyViewBean"
scope="request" />

<c:forEach var="mapEntry" items="${viewBean.map}">
<c:set var="theKey" value="${mapEntry.key}" />
<c:set var="anArrayList" value="${mapEntry.value}" />

<c:forEach var="car" items="${anArrayList}" >
.
.
.
</c:forEach>
</c:forEach>

I am receiving an exception at this point: "javax.servlet.ServletException: Don't know how to iterate over supplied "items" in <forEach>"

I believe that the problem is the "anArrayList" and that it doesn't know that it is an ArrayList that can be iterated over.

Any Ideas what the problem is???
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61066
    
  66

Which forEach is causing the problem?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
starrman777
Greenhorn

Joined: Mar 23, 2005
Posts: 6
I posted this question on another forum and the advice that I received was to find out what class the the Map's value actually is by doing this:

<c ut value="${anArrayList.class.name}"/>

Here is the post at the other forum
http://forum.java.sun.com/thread.jspa?threadID=633265&tstart=0

I tried that and figured out what to do from there.
Thanks!
starrman777
Greenhorn

Joined: Mar 23, 2005
Posts: 6
I guess the JSTL symbol got translated into an emoticon...
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61066
    
  66

The 'disable smilies' checkbox will prevent emoticon translation.

And how about posting your findings for anyone that might be having a similar issue?
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: JSTL's EL. Problem iterating over arraylist