aspose file tools*
The moose likes Struts and the fly likes Passing ArrayList Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Passing ArrayList" Watch "Passing ArrayList" New topic
Author

Passing ArrayList

Thara Visu
Ranch Hand

Joined: May 17, 2005
Posts: 87
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


Thara<br />SCJP 1.4 96%<br />SCBCD 1.3 96%
Brent Sterling
Ranch Hand

Joined: Feb 08, 2006
Posts: 948
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

Joined: May 17, 2005
Posts: 87
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

Joined: Aug 23, 2004
Posts: 57
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

Joined: Feb 15, 2005
Posts: 4864
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.


Merrill
Consultant, Sima Solutions
Thara Visu
Ranch Hand

Joined: May 17, 2005
Posts: 87
Thanks for all your inputs.
 
 
subject: Passing ArrayList