• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Imre Tokai
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 357
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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)
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65229
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Imre Tokai
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 357
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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>
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic