Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Passing ArrayList

 
Thara Visu
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • 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
 
Brent Sterling
Ranch Hand
Posts: 948
  • Mark post as helpful
  • send pies
  • 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
  • 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?
 
Nikhilesh Fonseca
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • 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 .
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Thanks for all your inputs.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic