• 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

Passing ArrayList

 
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,
I have an ArrayList that needs to be sent from JSP to the action class.
What is the best way to do it?
Should I essentially do it via the session object?

Thanks in advance
 
Ranch Hand
Posts: 948
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Maybe you could describe the situation in a bit more detail. Are you trying to submit data from the user's browser? An action forwards on to a jsp page which renders html. This is all done on the server side. The client side browser just knows about the rendered html.

- Brent
 
Thara Visu
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Brent,
I have a ArrayList that is returned from my Dao. I pass this ArrayList to my JSP using request.setAttribute. In my JSP i iterate and display the values. I now need to pass this ArrayList again to another action class. How can I do it other than setting the ArrayList in session? What is the best way?
 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you have a form submit which goes to an action class you can directly use request.setAttribute(Arraylist,"name"); ...I thnk
The request object is implicit to the jsp page ..
If you have a URL then I thnk only a session/application scope will help .
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The best way to do this is to put the ArrayList in your ActionForm bean and then use indexed properties to display them. If you use this technique, Struts will automatically populate the array list for you when the form is submitted.

There is something you have to be aware of, though. You will either have to put your ActionForm in session scope, or provide some special handling if you put it in request scope. Since an ActionForm that is in request scope has to be rebuilt from scratch after the form is submitted, you must provide "lazy initialization" methods to rebuild the ArrayList. This link provides some good information on how to do this.
 
Thara Visu
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for all your inputs.
 
Yes, my master! Here is the tiny ad you asked for:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic