You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Boaz Barkai <bo...@2train4.com> on 2004/02/29 11:21:17 UTC

Forwarding between actions

Hello 

I have a case where I wish to forward between actions, like the
following flow:

SetEditor.do->editorView.jsp -submit-->Save.do->SetView.do

Save.do uses a different form bean then SetView so how can I set the
SetView.do form bean?

I'm trying to keep the actions incapsulated so I do not wish to get the
form (or add myself) from the environment inside the Save.do action
(this is the solution I have - but I don't like it - it means that one
action should know about the parameters of another action inside the
action code.

Thanks 

Boaz. 



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


Re: Forwarding between actions

Posted by Niall Pemberton <ni...@blueyonder.co.uk>.
If your "adding" a customer, then in your "save customer" action, after you
have created the new customer, get the new identifier and store it in the
request.

Yes, as long as you don't have redirect="true" on your forward to the
"SetView.do" mapping, then it will repopulate. If you want to redirect, it
won't repopulate, and then you could set up the forward dynamically in your
action and append the id (e.g. customerNumber).

Maybe something like:

   String path = mapping.findForward("success").getPath()
                       + "?customerNumber="
                       + myForm.getCustomerNumber();
   return new ActionForward(path, true);



Niall

----- Original Message ----- 
From: "Boaz Barkai" <bo...@2train4.com>
To: "'Struts Users Mailing List'" <st...@jakarta.apache.org>
Sent: Sunday, February 29, 2004 1:50 PM
Subject: RE: Forwarding between actions


> So, you say that struts does repopulating of a from in forwarding
> between action, then my problem is that if there is a new Item (say
> customer) then the Id in the request is not the correct id (usually 0 or
> null) and I have updated the Id in the form used my the action.
>
> -----Original Message-----
> From: Niall Pemberton [mailto:niall.pemberton@blueyonder.co.uk]
> Sent: Sunday, February 29, 2004 3:28 PM
> To: Struts Users Mailing List
> Subject: Re: Forwarding between actions
>
> Boaz
>
> Struts should do its normal stuff when you forward to your SetView
> action.
> That is, it should create the form associated with SetView and populate
> it
> from the request.
>
> If, for example I have a "view customer" action - which gets called with
> a
> "customerNumber" parameter - struts will populate the customerNumber
> into my
> CustomerView form from the request. My action might then retrieve the
> customer details from the 'model' using the customerNumber from my form
> as a
> key and then output the full customerDetails to my CustomerView form,
> then
> forward to the appropriate jsp.
>
> If, I also have a "save customer" action - which gets the full set of
> customer details from submitting a form -struts will populate the
> customer
> details into my CustomerUpdate form from the request. My action might
> then
> update the customer details in the 'model' using the details from the
> CustomerUpdate  form (including the customerNumber from my form as a
> key).
>
> When I forward from the "save customer" to the "view customer" action,
> the
> customer number is still in the request, so the CustomerView form gets
> created, gets populated with my "customerNumber" and does the rest of
> its
> stuff, no problem.
>
> The key to this is that struts will create both forms AND populate both
> forms from the request and so both actions should work successfully
> without
> any knowledge of the other Action or its ActionForm. The only link being
> in
> the struts-config.xml where you define your forward from the "Save"
> action
> to the "View" action.
>
> Niall
>
> ----- Original Message ----- 
> From: "Boaz Barkai" <bo...@2train4.com>
> To: "'Struts Users Mailing List'" <st...@jakarta.apache.org>
> Sent: Sunday, February 29, 2004 12:52 PM
> Subject: RE: Forwarding between actions
>
>
> > The problem is that the forms are different
> >
> > <action path="/SetEditor" name="editForm" scope="request">
> > <forward name="success" path="/editorView.jsp" redirect="false"
> > />
> > </action>
> >
> > <action path="/Save" name="viewForm" input="/editorView.jsp"
> > scope="request">
> > <forward name="success" path="/SetView.do" redirect="true" />
> > </action>
> >
> > but the viewForm is not populated in this iteration
> >
> > Anyway, thanks for the help
> >
> >
> > -----Original Message-----
> > From: Mark Lowe [mailto:mark.lowe@talk21.com]
> > Sent: Sunday, February 29, 2004 12:56 PM
> > To: Struts Users Mailing List
> > Subject: Re: Forwarding between actions
> >
> >
> > So what do your action mappings look like?
> >
> > <action path="/SetEditor" name="editForm" scope="request">
> > <forward name="success" path="/editorView.jsp" redirect="false"
> > />
> > </action>
> >
> > <action path="/Save" name="editForm" input="/editorView.jsp"
> > scope="request">
> > <forward name="success" path="/SetView.do" redirect="true" />
> > </action>
> >
> > If this is the case then you only thing that the actions have to know
> > is what's contained in the mappings, which I think is okay because
> this
> > is what mappings are for (at least to my mind).
> >
> >
> >
> >
> > On 29 Feb 2004, at 11:21, Boaz Barkai wrote:
> >
> > > Hello
> > >
> > > I have a case where I wish to forward between actions, like the
> > > following flow:
> > >
> > > SetEditor.do->editorView.jsp -submit-->Save.do->SetView.do
> > >
> > > Save.do uses a different form bean then SetView so how can I set the
> > > SetView.do form bean?
> > >
> > > I'm trying to keep the actions incapsulated so I do not wish to get
> > the
> > > form (or add myself) from the environment inside the Save.do action
> > > (this is the solution I have - but I don't like it - it means that
> one
> > > action should know about the parameters of another action inside the
> > > action code.
> > >
> > > Thanks
> > >
> > > Boaz.
> > >
> > >
> > >
> > >
> ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> > > For additional commands, e-mail: struts-user-help@jakarta.apache.org
> > >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: struts-user-help@jakarta.apache.org
> >
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: struts-user-help@jakarta.apache.org
> >
> >
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
>
>



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


RE: Forwarding between actions

Posted by Boaz Barkai <bo...@2train4.com>.
So, you say that struts does repopulating of a from in forwarding
between action, then my problem is that if there is a new Item (say
customer) then the Id in the request is not the correct id (usually 0 or
null) and I have updated the Id in the form used my the action.

-----Original Message-----
From: Niall Pemberton [mailto:niall.pemberton@blueyonder.co.uk] 
Sent: Sunday, February 29, 2004 3:28 PM
To: Struts Users Mailing List
Subject: Re: Forwarding between actions 

Boaz

Struts should do its normal stuff when you forward to your SetView
action.
That is, it should create the form associated with SetView and populate
it
from the request.

If, for example I have a "view customer" action - which gets called with
a
"customerNumber" parameter - struts will populate the customerNumber
into my
CustomerView form from the request. My action might then retrieve the
customer details from the 'model' using the customerNumber from my form
as a
key and then output the full customerDetails to my CustomerView form,
then
forward to the appropriate jsp.

If, I also have a "save customer" action - which gets the full set of
customer details from submitting a form -struts will populate the
customer
details into my CustomerUpdate form from the request. My action might
then
update the customer details in the 'model' using the details from the
CustomerUpdate  form (including the customerNumber from my form as a
key).

When I forward from the "save customer" to the "view customer" action,
the
customer number is still in the request, so the CustomerView form gets
created, gets populated with my "customerNumber" and does the rest of
its
stuff, no problem.

The key to this is that struts will create both forms AND populate both
forms from the request and so both actions should work successfully
without
any knowledge of the other Action or its ActionForm. The only link being
in
the struts-config.xml where you define your forward from the "Save"
action
to the "View" action.

Niall

----- Original Message ----- 
From: "Boaz Barkai" <bo...@2train4.com>
To: "'Struts Users Mailing List'" <st...@jakarta.apache.org>
Sent: Sunday, February 29, 2004 12:52 PM
Subject: RE: Forwarding between actions


> The problem is that the forms are different
>
> <action path="/SetEditor" name="editForm" scope="request">
> <forward name="success" path="/editorView.jsp" redirect="false"
> />
> </action>
>
> <action path="/Save" name="viewForm" input="/editorView.jsp"
> scope="request">
> <forward name="success" path="/SetView.do" redirect="true" />
> </action>
>
> but the viewForm is not populated in this iteration
>
> Anyway, thanks for the help
>
>
> -----Original Message-----
> From: Mark Lowe [mailto:mark.lowe@talk21.com]
> Sent: Sunday, February 29, 2004 12:56 PM
> To: Struts Users Mailing List
> Subject: Re: Forwarding between actions
>
>
> So what do your action mappings look like?
>
> <action path="/SetEditor" name="editForm" scope="request">
> <forward name="success" path="/editorView.jsp" redirect="false"
> />
> </action>
>
> <action path="/Save" name="editForm" input="/editorView.jsp"
> scope="request">
> <forward name="success" path="/SetView.do" redirect="true" />
> </action>
>
> If this is the case then you only thing that the actions have to know
> is what's contained in the mappings, which I think is okay because
this
> is what mappings are for (at least to my mind).
>
>
>
>
> On 29 Feb 2004, at 11:21, Boaz Barkai wrote:
>
> > Hello
> >
> > I have a case where I wish to forward between actions, like the
> > following flow:
> >
> > SetEditor.do->editorView.jsp -submit-->Save.do->SetView.do
> >
> > Save.do uses a different form bean then SetView so how can I set the
> > SetView.do form bean?
> >
> > I'm trying to keep the actions incapsulated so I do not wish to get
> the
> > form (or add myself) from the environment inside the Save.do action
> > (this is the solution I have - but I don't like it - it means that
one
> > action should know about the parameters of another action inside the
> > action code.
> >
> > Thanks
> >
> > Boaz.
> >
> >
> >
> >
---------------------------------------------------------------------
> > To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: struts-user-help@jakarta.apache.org
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
>
>



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




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


Re: Forwarding between actions

Posted by Niall Pemberton <ni...@blueyonder.co.uk>.
Boaz

Struts should do its normal stuff when you forward to your SetView action.
That is, it should create the form associated with SetView and populate it
from the request.

If, for example I have a "view customer" action - which gets called with a
"customerNumber" parameter - struts will populate the customerNumber into my
CustomerView form from the request. My action might then retrieve the
customer details from the 'model' using the customerNumber from my form as a
key and then output the full customerDetails to my CustomerView form, then
forward to the appropriate jsp.

If, I also have a "save customer" action - which gets the full set of
customer details from submitting a form -struts will populate the customer
details into my CustomerUpdate form from the request. My action might then
update the customer details in the 'model' using the details from the
CustomerUpdate  form (including the customerNumber from my form as a key).

When I forward from the "save customer" to the "view customer" action, the
customer number is still in the request, so the CustomerView form gets
created, gets populated with my "customerNumber" and does the rest of its
stuff, no problem.

The key to this is that struts will create both forms AND populate both
forms from the request and so both actions should work successfully without
any knowledge of the other Action or its ActionForm. The only link being in
the struts-config.xml where you define your forward from the "Save" action
to the "View" action.

Niall

----- Original Message ----- 
From: "Boaz Barkai" <bo...@2train4.com>
To: "'Struts Users Mailing List'" <st...@jakarta.apache.org>
Sent: Sunday, February 29, 2004 12:52 PM
Subject: RE: Forwarding between actions


> The problem is that the forms are different
>
> <action path="/SetEditor" name="editForm" scope="request">
> <forward name="success" path="/editorView.jsp" redirect="false"
> />
> </action>
>
> <action path="/Save" name="viewForm" input="/editorView.jsp"
> scope="request">
> <forward name="success" path="/SetView.do" redirect="true" />
> </action>
>
> but the viewForm is not populated in this iteration
>
> Anyway, thanks for the help
>
>
> -----Original Message-----
> From: Mark Lowe [mailto:mark.lowe@talk21.com]
> Sent: Sunday, February 29, 2004 12:56 PM
> To: Struts Users Mailing List
> Subject: Re: Forwarding between actions
>
>
> So what do your action mappings look like?
>
> <action path="/SetEditor" name="editForm" scope="request">
> <forward name="success" path="/editorView.jsp" redirect="false"
> />
> </action>
>
> <action path="/Save" name="editForm" input="/editorView.jsp"
> scope="request">
> <forward name="success" path="/SetView.do" redirect="true" />
> </action>
>
> If this is the case then you only thing that the actions have to know
> is what's contained in the mappings, which I think is okay because this
> is what mappings are for (at least to my mind).
>
>
>
>
> On 29 Feb 2004, at 11:21, Boaz Barkai wrote:
>
> > Hello
> >
> > I have a case where I wish to forward between actions, like the
> > following flow:
> >
> > SetEditor.do->editorView.jsp -submit-->Save.do->SetView.do
> >
> > Save.do uses a different form bean then SetView so how can I set the
> > SetView.do form bean?
> >
> > I'm trying to keep the actions incapsulated so I do not wish to get
> the
> > form (or add myself) from the environment inside the Save.do action
> > (this is the solution I have - but I don't like it - it means that one
> > action should know about the parameters of another action inside the
> > action code.
> >
> > Thanks
> >
> > Boaz.
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: struts-user-help@jakarta.apache.org
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
>
>



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


RE: Forwarding between actions

Posted by Boaz Barkai <bo...@2train4.com>.
The problem is that the forms are different 

<action path="/SetEditor" name="editForm" scope="request">
	<forward name="success" path="/editorView.jsp" redirect="false"
/>
</action>

<action path="/Save" name="viewForm" input="/editorView.jsp" 
scope="request">
	<forward name="success" path="/SetView.do" redirect="true" />
</action>

but the viewForm is not populated in this iteration

Anyway, thanks for the help 


-----Original Message-----
From: Mark Lowe [mailto:mark.lowe@talk21.com] 
Sent: Sunday, February 29, 2004 12:56 PM
To: Struts Users Mailing List
Subject: Re: Forwarding between actions 


So what do your action mappings look like?

<action path="/SetEditor" name="editForm" scope="request">
	<forward name="success" path="/editorView.jsp" redirect="false"
/>
</action>

<action path="/Save" name="editForm" input="/editorView.jsp" 
scope="request">
	<forward name="success" path="/SetView.do" redirect="true" />
</action>

If this is the case then you only thing that the actions have to know 
is what's contained in the mappings, which I think is okay because this 
is what mappings are for (at least to my mind).




On 29 Feb 2004, at 11:21, Boaz Barkai wrote:

> Hello
>
> I have a case where I wish to forward between actions, like the
> following flow:
>
> SetEditor.do->editorView.jsp -submit-->Save.do->SetView.do
>
> Save.do uses a different form bean then SetView so how can I set the
> SetView.do form bean?
>
> I'm trying to keep the actions incapsulated so I do not wish to get
the
> form (or add myself) from the environment inside the Save.do action
> (this is the solution I have - but I don't like it - it means that one
> action should know about the parameters of another action inside the
> action code.
>
> Thanks
>
> Boaz.
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
>


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




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


Re: Forwarding between actions

Posted by Mark Lowe <ma...@talk21.com>.
So what do your action mappings look like?

<action path="/SetEditor" name="editForm" scope="request">
	<forward name="success" path="/editorView.jsp" redirect="false" />
</action>

<action path="/Save" name="editForm" input="/editorView.jsp" 
scope="request">
	<forward name="success" path="/SetView.do" redirect="true" />
</action>

If this is the case then you only thing that the actions have to know 
is what's contained in the mappings, which I think is okay because this 
is what mappings are for (at least to my mind).




On 29 Feb 2004, at 11:21, Boaz Barkai wrote:

> Hello
>
> I have a case where I wish to forward between actions, like the
> following flow:
>
> SetEditor.do->editorView.jsp -submit-->Save.do->SetView.do
>
> Save.do uses a different form bean then SetView so how can I set the
> SetView.do form bean?
>
> I'm trying to keep the actions incapsulated so I do not wish to get the
> form (or add myself) from the environment inside the Save.do action
> (this is the solution I have - but I don't like it - it means that one
> action should know about the parameters of another action inside the
> action code.
>
> Thanks
>
> Boaz.
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
>


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