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

Sending a List to another Action class

Songezo Nkukwana
Ranch Hand

Joined: Nov 27, 2008
Posts: 51
Hi,

say i have a class box with two members (String color, int size) ... My Action1 creates a collection boxes read from a DB... I then need to send this to Form1.hsp as a request, then forward these boxes (collection/list) from Form1.jsp (or action1) to Action2 ... How can one do this?

Can 1 send a collection from one action to another?

PS. Action1 has mapping.findForward("action2"); and this works fine, but not the transferring of the list ... A code example would help...

Thanks in Advance
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

The only thing HTTP requests can send to the server are strings. Period.

There are various options: store the list in the application or session context, re-create the list from request parameters, and so on.

If the list read from the DB is the same across the entire application storing it in the application context may make the most sense. If you want to send a list of values selected from that list, like a collection of select box options, all you can do is send, for example, the collection of IDs chosen.

In S2, type conversion can be used to re-create the actual objects represented by the collection of IDs, making it *appear* as though the request included actual objects--but they're being created from the strings sent by the browser.

So depending on what your actual requirements are there are a variety of solutions.
Songezo Nkukwana
Ranch Hand

Joined: Nov 27, 2008
Posts: 51
My attempt of using the session ...


Here's part of my first Action class



QualsAction is another action class. It also needs jobQuals list.

i tried getting this in QualsAction ...



PROBLEM: I get a NullPointerException sometimes ...For some reason the list is not always put on the session, or the casting isn't always working properly ..
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Sending a List to another Action class
 
Similar Threads
Value of ActionForm in second Action that is chained
Communication between Actions classes
html:image - running into an infinite loop
putting a value in request scope in struts2 from jsp
Pre-populate form