You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Michael Jouravlev <jm...@gmail.com> on 2005/05/09 00:47:28 UTC

Re: action to action

If someone told you that eating with the left hand is discouraged,
would you care? ;) Just do what you think is best, if it does not hurt
other people ;)

I submitted my approach to action chaining here in the wiki:
  http://wiki.apache.org/struts/StrutsCatalogInputOutputSeparation

I think that I provided enough arguments for doing that. If these
arguments is not enough, I can add more ;)

Michael.

On 5/8/05, rmanchu <rm...@gmail.com> wrote:
> 
> i have to following scenario.
> 
> interface1 =>action1 => action2 => interface2
> 
> is calling another action from an action discouraged in struts?
> 
> what's the best solution for this? 1.2.4 to 1.3-dev
> 
> thanx
> riyaz

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


Re: action to action

Posted by rmanchu <rm...@gmail.com>.
oh man. thanx. changing all to POST now ....

thanx :)
riyaz


Michael Jouravlev wrote:
> If you are submitting a form, and have a button, I do not see the
> reason not to use POST. If you have a link like "Delete Item" in the
> list, then I may see that you may be tempted to use GET. At the end it
> is up to you, you are the designer. But sometimes it is important to
> differentiate between POST and GET. For example, if you have a single
> action, which you submit to, and which displays the result, you may
> use POST for submit and GET to load the result page. So, if you use
> GET to submit, you would not be able to differentiate input from
> output. It is another question why would one want to use one action
> for input and output.
> 
> Here is an example. I have a wizard, which has several pages, and is
> controlled by one action. I submit input data to the action using
> POST. Action sees that request method is POST, and it accepts input
> data and modifies model, then it redirects to itself. So, when it
> recieves redirected request, it has GET type and action understands,
> that now it has to show the page, corresponding to the wizard. Easy.
> 
> Another great thing about using one action is that if you use exactly
> same URL, then MSIE and Mozilla do not add pages to page history. This
> is great when you modify some data several times. You change some
> data, sumbit it, it is wrong, the same page is displayed. Then you
> change it, sumbit it, it is wrong, the same page is displayed. You can
> do this several times. Then you tired, and you click Back, and you
> return from this form immediately, because it was stored in browser
> session history only once.
> 
> On 5/8/05, rmanchu <rm...@gmail.com> wrote:
> 
>>hi.
>>
>>thanx to all who wrote back.
>>
>>after having read the replies and links provided i'm going to use the
>>Redirect-after-Post method in my app. i would have to craft a dynamic
>>Forward with the right params which i think for my needs is a much
>>shorter/easier route. thanx to all.
>>
>>now i have a different question :)
>>
>>all you guys and the articles _seemed_ to stress the POST method for
>>form submission. my default is use the GET method if there is no file
>>uploads. am i setting myself for a big fall by doing this?
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
> 


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


Re: action to action

Posted by Michael Jouravlev <jm...@gmail.com>.
If you are submitting a form, and have a button, I do not see the
reason not to use POST. If you have a link like "Delete Item" in the
list, then I may see that you may be tempted to use GET. At the end it
is up to you, you are the designer. But sometimes it is important to
differentiate between POST and GET. For example, if you have a single
action, which you submit to, and which displays the result, you may
use POST for submit and GET to load the result page. So, if you use
GET to submit, you would not be able to differentiate input from
output. It is another question why would one want to use one action
for input and output.

Here is an example. I have a wizard, which has several pages, and is
controlled by one action. I submit input data to the action using
POST. Action sees that request method is POST, and it accepts input
data and modifies model, then it redirects to itself. So, when it
recieves redirected request, it has GET type and action understands,
that now it has to show the page, corresponding to the wizard. Easy.

Another great thing about using one action is that if you use exactly
same URL, then MSIE and Mozilla do not add pages to page history. This
is great when you modify some data several times. You change some
data, sumbit it, it is wrong, the same page is displayed. Then you
change it, sumbit it, it is wrong, the same page is displayed. You can
do this several times. Then you tired, and you click Back, and you
return from this form immediately, because it was stored in browser
session history only once.

On 5/8/05, rmanchu <rm...@gmail.com> wrote:
> 
> hi.
> 
> thanx to all who wrote back.
> 
> after having read the replies and links provided i'm going to use the
> Redirect-after-Post method in my app. i would have to craft a dynamic
> Forward with the right params which i think for my needs is a much
> shorter/easier route. thanx to all.
> 
> now i have a different question :)
> 
> all you guys and the articles _seemed_ to stress the POST method for
> form submission. my default is use the GET method if there is no file
> uploads. am i setting myself for a big fall by doing this?

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


Re: action to action

Posted by rmanchu <rm...@gmail.com>.
hi.

thanx to all who wrote back.

after having read the replies and links provided i'm going to use the 
Redirect-after-Post method in my app. i would have to craft a dynamic 
Forward with the right params which i think for my needs is a much 
shorter/easier route. thanx to all.

now i have a different question :)

all you guys and the articles _seemed_ to stress the POST method for 
form submission. my default is use the GET method if there is no file 
uploads. am i setting myself for a big fall by doing this?

thanx
riyaz

Michael Jouravlev wrote:
> Yes, redirect produces new request. It will have GET type, which is
> important. Yes, you will lose field values of your form, if the form
> bean has request scope. The question is, do you really need to
> preserve these values?

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


Re: action to action

Posted by Michael Jouravlev <jm...@gmail.com>.
Yes, redirect produces new request. It will have GET type, which is
important. Yes, you will lose field values of your form, if the form
bean has request scope. The question is, do you really need to
preserve these values?

Consider this: instead of having business object somewhere on the
business layer, and having form bean properties on the presentation
layer you have just a business object with properties. It can be a
persistent object in the database, or a "working copy" of the object,
in the RAM. Your form bean has reference to the working copy. You
store working copy in the session. If you want, the "working copy" is
a business DTO or whatever it is called. Thus, your presentation layer
is made aware of your business classes. Some consider this as a
drawback, because when your business classes change, you have to
update presentataion classes. But I think it is really handy.

You pass object ID with redirection request, yes you will need to
create a new ActionForward object and to append object ID as a
payload. But this totally frees you up afterwards! You have a "edit"
or "view" action which does not care where request came from and what
are the current values of form fields. It just receives object ID in
the request, and either shows object data from the session, if object
is already there, or loads object from the database, sticks it into
the session and shows it.

I understand, that this approach may require to change your
application architecture, so this is just a food for thought. So, what
you can do in your current application?

You can either set your form bean to session scope, this way it will
not lose field values. Or, you can pass values in the redirected
request, this is what Spring's RedirectView does. I pass just object
ID in the redirected request, instead of passing all object values.

If you interested, read the article
  http://www.theserverside.com/articles/article.tss?l=RedirectAfterPost2
it has the link to the source code. The source code may seem a little
overboard. I am in the process of refactoring this code to make it
simpler and more generic. I want to make a library out, I hope it will
help.

Michael.

On 5/8/05, rmanchu <rm...@gmail.com> wrote:
> 
> thanx michael. have one question though
> 
> <action path  = "/storeItem"
>    type  = "com.superinterface.items.StoreItemAction"
>    name  = "itemFormInput">
>    <forward name="itemStored" path="/itemList.do" redirect="true"/>
>    <forward name="storeError" path="/editItem.do" redirect="true"/>
> </action>
> 
> in the example above, the redirect would produce a new request object
> right? which means i'll lost some vars that i already have from my
> "action1" which r required in "action2"
> 
> i'm thinking i shud redirect with the three parameters that i need - ie
> create the forward dynamically. am i right?
> 
> perhaps there's a shorter way?
> 
> thanx for the quick reply
> riyaz
> 
> Michael Jouravlev wrote:
> > Michael.
> >
> >>i have to following scenario.
> >>
> >>interface1 =>action1 => action2 => interface2
> >>

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


Re: action to action

Posted by rmanchu <rm...@gmail.com>.
thanx michael. have one question though

<action path  = "/storeItem"
   type  = "com.superinterface.items.StoreItemAction"
   name  = "itemFormInput">
   <forward name="itemStored" path="/itemList.do" redirect="true"/>
   <forward name="storeError" path="/editItem.do" redirect="true"/>
</action>

in the example above, the redirect would produce a new request object 
right? which means i'll lost some vars that i already have from my 
"action1" which r required in "action2"

i'm thinking i shud redirect with the three parameters that i need - ie 
create the forward dynamically. am i right?

perhaps there's a shorter way?

thanx for the quick reply
riyaz


Michael Jouravlev wrote:
> Michael.
> 
>>i have to following scenario.
>>
>>interface1 =>action1 => action2 => interface2
>>

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