jQuery in Action, 2nd edition*
The moose likes JSP and the fly likes Spring: ArrayList instead of <c:forEach in jsp page Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Spring: ArrayList instead of <c:forEach in jsp page" Watch "Spring: ArrayList instead of <c:forEach in jsp page" New topic
Author

Spring: ArrayList instead of <c:forEach in jsp page

Imre Tokai
Ranch Hand

Joined: Jun 04, 2008
Posts: 130
Hello!


I want to use java.util.ArrayList instead of <c:forEach in jsp page, because i need it in javascript
This is working well:


but when i try with:


I get NullPointerException.

How can i use the passed array with java.util.ArrayList in jsp page?


Regards
Omar Al Kababji
Ranch Hand

Joined: Jan 13, 2009
Posts: 357
when you use the ${items} it dosen't mean that the items arraylist is in the request scope it could be in page, request, session, application scopes i would suggest to double check if the items are in the request scope, may be they are in the session scope ;).

remember that when using EL it will go and search for the attribute in any in the following sequence .. page --> request --> session --> application


(peace)


Omar Al Kababji - Electrical & Computer Engineer
[SCJP - 90% - Story] [SCWCD - 94% - Story] [SCBCD - 80% - Story] | My Blog
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61451
    
  67

Imre Tokai wrote:I want to use java.util.ArrayList instead of <c:forEach in jsp page, because i need it in javascript
This makes little sense. What is it that you are really trying to do?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Imre Tokai
Ranch Hand

Joined: Jun 04, 2008
Posts: 130
Thanks for your answers!


I tried with page,request,session, application -no success.

I'm using Spring framework; I want to pass an ArrayList of objects to the jsp page via SomeController's handleRequestInternal method.



It's working fine when I'm just writing contents of the objects from list to the page using c:forEach
But when I want to use request.getAttribute("items"); I get exception.

If I'm able to pull the values out with <c:forEach items="${items}" var="item">, why can't I do that with
<% java code parts inside jsp page%>? How can I solve this?


Regards
Omar Al Kababji
Ranch Hand

Joined: Jan 13, 2009
Posts: 357
are you getting a NullPointerException or another type of exception ? can you post the stack trace of the exception please ?


(peace)
Imre Tokai
Ranch Hand

Joined: Jun 04, 2008
Posts: 130
SOLVED!


It seems that it's not possible to have:

on the same page.
I had that foreach for data preview. When i removed it the page started to work correctly.

Thank you for leading me to the solution!


Regards>
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Spring: ArrayList instead of <c:forEach in jsp page