Win a copy of Pragmatic AI this week in the Artificial Intelligence forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

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

 
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
 
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)
 
Author and ninkuma
Marshal
Posts: 66790
168
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>
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!