I posted a message on this not long ago on struts-dev. It's archived here:

http://www.mail-archive.com/struts-dev@jakarta.apache.org/msg01351.html

Here's an outline of what I do.

1) The forwarding action (action A) explicitly creates a new form bean of
the type used by the action to be forwarded to (action B), and populates it
with the parameters it wants to send.

2) Action A then sets this bean up as a request attribute under a well-known
name - say "forwardRequestFormBean". It can't store it under the same name
as Struts uses, because Struts will call reset() on that form bean and
populate it from the request, which would wipe out the data set up in step 1
above.

3) Action A then forwards to a special path that looks like this:

    <forward name="actionBChain" path="/actionB.do?chain=true"/>

4) The form bean for action B checks for chaining in its validate method
like this:

    if (getChain()) return null;

This is a little strange. What's going on is that Struts is going to try to
validate the form bean it created and populated with the request parameters.
Those parameters will, in fact, be those from the original request for
action A, along with chain=true from my forward path. I don't want Struts to
try to validate that bean at all, because that's not the bean that has the
data I want. So I add the chain parameter to the request and have the form
bean check for it and skip validation in that case. (The reset method of the
form bean sets the chain property to false.)

5) The perform() method for action B first looks to see if there is a form
bean for it stored as a request attribute under the key
"forwardRequestFormBean". If there is such a bean, that is the one it uses
to determine what to do. If there is no such bean, then it uses the one that
was passed to perform() by Struts.

This is all a little convoluted, but it was the most reliable way I could
come up with for avoiding the issues arising from the combining of request
parameters.

One thing I have not done, which would be a nice enhancement, would be to
dynamically determine the type of the form bean to be created in step 1.
This could be done by looking at the forward object (actionBChain in the
example above), finding the mapping from that, and finding the form bean
object from the mapping. As it is, my action A "just knows" the class used
for action B's form bean.

Hope this helps.

--
Martin Cooper


----- Original Message -----
From: "Andrew Steady" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Thursday, May 24, 2001 6:58 AM
Subject: Re: removing request parameters before action forward


> I have a similar question which perhaps could be asked at the same time.
>
> I have a JSP that submits to an Action with a certain set of parameters,
> the ActionClass then forwards to another ".do" if succesful, when this
> ".do" is called the corresponding form bean is created and populated with
> request data. However the data in the request object was never meant for
> that form bean it was only for the form bean belonging to the original
> ".do". A side affect is that if the 2nd bean has any matching data names
to
> the first it will get populated with data. I understand you could make
sure
> that all the names were different but that rather detracts from the
> atomicity of the two ".do" actions.
>
> Am I looking through something obvious? Anyone solved this before?
>
> Andy S
>
>
>
>
>
>
>
> [EMAIL PROTECTED] on 18/04/2001 12:47:01
>
> Please respond to [EMAIL PROTECTED]
>
> To:   [EMAIL PROTECTED]
> cc:    (bcc: Andrew Steady/Swindon01/Domino01/Kinesis)
> Subject:  removing request parameters before action forward
>
>
>
>
> Hello to all,
> I don't know how to remove request parameters just before leaving a
> perform(...) method.
> 1) Is this a bad practice or wrong design?
> 2) if not, how can I do this?
> What I'am trying to do:
> A jsp page displays some items. If one clicks an item, the same page shows
> again with an incremented item count.
> The <html:link...>-tag includes the item id as an url parameter. The
> perform
> method of the action class looks for this url parameter, increments the
> corresponding item count in the action form and forwards back to the jsp
> page.
> Everything works fine, but the url parameter (the complete url) is also
> forwarded to the jsp page. Sometimes this doesn't matter (or even should
be
> like that), but in this case, pushing the reload button increments the
item
> count again.
> Could anyone give me a hint or even a solution?
> Thank You
> Stefan
> PS: I feel this was asked before, but I could not locate similar questions
> in the archive. Sorry.
> --
> Stefan Seidel
>
>
>
>
>
>
>


Reply via email to