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 <[EMAIL PROTECTED]> 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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to