You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Mitchell, Steven C" <St...@umb.com> on 2005/07/08 14:34:25 UTC

Passing data between action forms

I'm curious to hear what other people are doing regarding the passing of
data between actions.  Take for example an advanced search page with
validation, drop down lists, the works.  Upon successful validation the
user should flow to a search results page.  Assume the results page is
part of something bigger that may require additional server-side
processing.  
 
In the past I have put the search results list on the same action form
as the search criteria and just forwarded to a different JSP from the
same action.  There are times when I would prefer to forward to a
different action/form pair, especially if their is potential for
additional processing.  I suppose I could put the form in the session
and define a different action that uses the same form to achieve some
modularity, but I would prefer to be able to just hand-off the search
results to a separate action/form pair.  Is there an elegant way to do
that in Struts?  Am I just trying to make this overly complex?

Re: Passing data between action forms

Posted by Wendy Smoak <ja...@wendysmoak.com>.
From: "Michael Jouravlev" <jm...@gmail.com>

> It will sound like a scratched vinil, but I believe that forwarding
> from search page to result page is not the right thing to do, because
> whenever you refresh result page, you run the search query again. So,
> it should be a redirect.

I think so, too.  I was just looking at the old project I wrote about, and I
could dispense with setting those request attributes if I just constructed
the URL to the ResolveName action, and redirected to it.  Back then, I was
just glad it worked. :)

-- 
Wendy Smoak


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Passing data between action forms

Posted by Michael Jouravlev <jm...@gmail.com>.
On 7/8/05, Mitchell, Steven C <St...@umb.com> wrote:
> I'm curious to hear what other people are doing regarding the passing of
> data between actions.  Take for example an advanced search page with
> validation, drop down lists, the works.  Upon successful validation the
> user should flow to a search results page.  Assume the results page is
> part of something bigger that may require additional server-side
> processing.
> 
> In the past I have put the search results list on the same action form
> as the search criteria and just forwarded to a different JSP from the
> same action.

It will sound like a scratched vinil, but I believe that forwarding
from search page to result page is not the right thing to do, because
whenever you refresh result page, you run the search query again. So,
it should be a redirect.

I see the following choices:

* pass search results in request
* pass search results in session
* pass results in session, and navigational info like current page,
first line on page, last line on page, etc. in request.

Result page for search form does not have to be stateful. What do you
expect, if you navigate to result page, typing its location in address
bar? If it does not have to keep previous search results, than as long
as you able to fit everything into request, it probably would be the
best.

If you decide to use redirect and request, action forms or request
object will not help you. You would have to append it manually to URL,
since you cannot simply stick it into request object, it is destroyed
and recreated with each request.

P.S. If you have simple string results, maybe you can use some kind of
hack, sticking results into session under error message key, so after
the results accessed, they are removed by RequestProcessor
automatically?

Did not give this a lot of thought. But this idea seems promising: to
define types/instances/keys of ojects, which would be removed
automatically after accessed.

Michael.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Passing data between action forms

Posted by Wendy Smoak <ja...@wendysmoak.com>.
From: "Mitchell, Steven C" <St...@umb.com>
> I'm curious to hear what other people are doing regarding the passing of
> data between actions.  Take for example an advanced search page with
> validation, drop down lists, the works.  Upon successful validation the
> user should flow to a search results page.  Assume the results page is
> part of something bigger that may require additional server-side
> processing.

I'll be interested in other responses... I had to make this work in my first
Struts webapp, three years ago (!) now.  I doubt I got it "right," but it
does work.

I have a 'person lookup' that has to be shared across many forms.  Anywhere
there is a text box with an 'add person' button, it has to go off to
resolution, and most importantly, it has to come back and add the selected
person to the right original form.

Struts doesn't have a concept of 'go back where you came from' so I set
request attributes before forwarding to the ResolveName action.  And I do
chain them:
   <action    path="/editReminder" ... >
       <forward name="resolution"     path="/resolveName.do" />
       <forward name="saved"           path="reminder.confirm" />
    </action>

This is the one case where I couldn't get around going from
Action-to-Action, which is (or was, I'm not so sure anymore...) frowned
upon.

In the LookupDispatchAction, which uses userAction to switch methods, I set
request attributes for nameOrId, returnTo, and userAction.

Then ResolveNameAction picks up 'nameOrId' and does its thing, and in the
resulting JSP, I just used a plain old HTML form:
   <form action="<c:out value="${returnTo}"/>" method="POST">
   <input type="hidden" name="userAction" value="<c:out
value="${userAction}"/>" />
   ...then iterate through the choices...

When the user submits that form, you're back to the original Action.

HTH,
-- 
Wendy Smoak


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Passing data between action forms

Posted by BH...@powersystems.rockwell.com.
Typically, I will create a SearchBean with all of the search parameters on
it.  Included in this bean is a collection to store the results in.

On the ActionForm, I will include the SearchBean as a parameter on the
search bean.  On the JSP, I use nested tags or the . notation (<html:text
property="search.name"...)  That way I can pass the SearchBean to a Dao
Helper, ActionForm, or Business Logic Utility with a single get/set method.




                                                                           
             "Mitchell, Steven                                             
             C"                                                            
             <Steven.Mitchell@                                          To 
             umb.com>                  <us...@struts.apache.org>            
                                                                        cc 
             07/08/2005 08:34                                              
             AM                                                    Subject 
                                       Passing data between action forms   
                                                                           
             Please respond to                                             
               "Struts Users                                               
               Mailing List"                                               
             <user@struts.apac                                             
                  he.org>                                                  
                                                                           
                                                                           




I'm curious to hear what other people are doing regarding the passing of
data between actions.  Take for example an advanced search page with
validation, drop down lists, the works.  Upon successful validation the
user should flow to a search results page.  Assume the results page is
part of something bigger that may require additional server-side
processing.

In the past I have put the search results list on the same action form
as the search criteria and just forwarded to a different JSP from the
same action.  There are times when I would prefer to forward to a
different action/form pair, especially if their is potential for
additional processing.  I suppose I could put the form in the session
and define a different action that uses the same form to achieve some
modularity, but I would prefer to be able to just hand-off the search
results to a separate action/form pair.  Is there an elegant way to do
that in Struts?  Am I just trying to make this overly complex?