• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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)
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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>
 
I am going down to the lab. Do NOT let anyone in. Not even this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic