You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Chris Cheshire <ch...@gmail.com> on 2006/03/03 01:26:08 UTC

multiple-step form processing

I want to set up a form that is entered over 3 successive pages.

I have a single form bean for all of them that includes all of the
fields, and the validate method only validates the fields that were
implemented on each particular step.

Step 2 will present 1 of 2 sub-forms, depending on an option selected
on the bottom of form 1 (ie, either enter credit card info, or bank
account info).

I was thinking of using a DispatchAction to process each step and move
to the next part of the form sequence, but my problem is with
automatic validation and the struts-config declarations. I can only
declare one input per action, so if validation fails on any step the
controller would always redirect back to that specified input page  -
which might not be the one the user was on.

Do I actually need to set up multiple actions each with their own
input and process the steps through there or is there a way I can do
this with a single DispatchAction?

Or better yet, can I set validation to false in struts-config and then
call the validation routine myself inside the action and then forward
back to the correct input page if it fails?

Thanks

Chris

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


Re: multiple-step form processing

Posted by Chris Cheshire <ch...@gmail.com>.
Thanks Laurie, I didn't even think of that.

I am going to explore what Michael posted, because I like the tidiness
of that solution.

Chris

On 3/3/06, Laurie Harper <la...@holoweb.net> wrote:
> Just for balance ;-) I'll also point out that you don't *have* to
> disable automatic validation to achieve your goal; there are approaches
> that will allow you to retain that functionality, too.
>
> One possibility is to point the 'input' attribute to the same
> DispatchAction and have one of the methods in that determine which JSP
> to forward to.
>
> L.
>

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


Re: multiple-step form processing

Posted by Laurie Harper <la...@holoweb.net>.
Just for balance ;-) I'll also point out that you don't *have* to 
disable automatic validation to achieve your goal; there are approaches 
that will allow you to retain that functionality, too.

One possibility is to point the 'input' attribute to the same 
DispatchAction and have one of the methods in that determine which JSP 
to forward to.

L.

Chris Cheshire wrote:
> Thank you for your help, I'll give all this a try :)
> 
> Chris
> 
> On 3/2/06, Michael Jouravlev <jm...@gmail.com> wrote:
>> On 3/2/06, Chris Cheshire <ch...@gmail.com> wrote:
>>> Thanks Michael, both of those are helpful.
>>>
>>> I have a few extra questions though:
>>>
>>> Regarding ActionDispatcher -
>>> * The ParameterListActionDispatcher class isn't in the 1.2.8 struts
>>> distribution that I downloaded, and is linked as a bugfix. Do I need
>>> to download the entire struts source, add this in and recompile, or is
>>> there an easier way?
>> ParameterListActionDispatcher is a proposal for upcoming Struts
>> release. The more people use it and find it useful, the more chances
>> that it will be included. So, try it and vote for it if you like it:
>> http://issues.apache.org/bugzilla/show_bug.cgi?id=38343 I hope you
>> will like it, I think it is the best known solution for event dispatch
>> in Struts.
>>
>> If you use Struts 1.2.7+, all you need is only
>> ParameterListActionDispatcher class. Download it and compile it along
>> with your project. If you use older Struts version than you will need
>> base ActionDispatcher as well, but nothing more.
>>
>>> Regarding DataEntryForm -
>>> * In sections 6 & 7 it describes a class
>>> ParameterMappingDispatchAction that I also don't see in the
>>> distribution (nor in the javadocs online). Is this referring to the
>>> ParameterListActionDispatcher class or something else? Conceptually it
>>> seems to be describing the same thing. If not is there an example of
>>> what step 7 is describing?
>> Right, I have to fix that. ParameterMappingDispatchAction was an
>> initial patch, then Paul went with ParameterListActionDispatcher which
>> is better because you can use any Action class, you do not have to
>> derive your Action from some other dispatch class anymore. So
>> disregard ParameterMappingDispatchAction, I will fix the wiki page
>> later.
>>
>>> All that aside, when I turn off automatic validation, can I still call
>>> the validation manually in my action code? ie. Something like :
>>>
>>> ActionErrors errors = form.validate(mapping, request);
>>> if (!errors.isEmpty()) {
>>>     // determine which forward key to use based upon which step I am
>>> in the process
>>>     forward = mapping.findForward(forwardKey);
>>>     saveErrors(request, errors);
>>>     return forward;
>>> }
>> Of course. This is exactly how you do it, perfect.
>>
>>> Is there anything else I need to do to validate the form manually?
>> No. You may want to check errors for null, but it depends on how you
>> implemented validate() method.
>>
>> Michael.
>>
>> ---------------------------------------------------------------------
>> 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: multiple-step form processing

Posted by Chris Cheshire <ch...@gmail.com>.
Thank you for your help, I'll give all this a try :)

Chris

On 3/2/06, Michael Jouravlev <jm...@gmail.com> wrote:
> On 3/2/06, Chris Cheshire <ch...@gmail.com> wrote:
> > Thanks Michael, both of those are helpful.
> >
> > I have a few extra questions though:
> >
> > Regarding ActionDispatcher -
> > * The ParameterListActionDispatcher class isn't in the 1.2.8 struts
> > distribution that I downloaded, and is linked as a bugfix. Do I need
> > to download the entire struts source, add this in and recompile, or is
> > there an easier way?
>
> ParameterListActionDispatcher is a proposal for upcoming Struts
> release. The more people use it and find it useful, the more chances
> that it will be included. So, try it and vote for it if you like it:
> http://issues.apache.org/bugzilla/show_bug.cgi?id=38343 I hope you
> will like it, I think it is the best known solution for event dispatch
> in Struts.
>
> If you use Struts 1.2.7+, all you need is only
> ParameterListActionDispatcher class. Download it and compile it along
> with your project. If you use older Struts version than you will need
> base ActionDispatcher as well, but nothing more.
>
> > Regarding DataEntryForm -
> > * In sections 6 & 7 it describes a class
> > ParameterMappingDispatchAction that I also don't see in the
> > distribution (nor in the javadocs online). Is this referring to the
> > ParameterListActionDispatcher class or something else? Conceptually it
> > seems to be describing the same thing. If not is there an example of
> > what step 7 is describing?
>
> Right, I have to fix that. ParameterMappingDispatchAction was an
> initial patch, then Paul went with ParameterListActionDispatcher which
> is better because you can use any Action class, you do not have to
> derive your Action from some other dispatch class anymore. So
> disregard ParameterMappingDispatchAction, I will fix the wiki page
> later.
>
> > All that aside, when I turn off automatic validation, can I still call
> > the validation manually in my action code? ie. Something like :
> >
> > ActionErrors errors = form.validate(mapping, request);
> > if (!errors.isEmpty()) {
> >     // determine which forward key to use based upon which step I am
> > in the process
> >     forward = mapping.findForward(forwardKey);
> >     saveErrors(request, errors);
> >     return forward;
> > }
>
> Of course. This is exactly how you do it, perfect.
>
> > Is there anything else I need to do to validate the form manually?
>
> No. You may want to check errors for null, but it depends on how you
> implemented validate() method.
>
> Michael.
>
> ---------------------------------------------------------------------
> 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: multiple-step form processing

Posted by Michael Jouravlev <jm...@gmail.com>.
On 3/2/06, Chris Cheshire <ch...@gmail.com> wrote:
> Thanks Michael, both of those are helpful.
>
> I have a few extra questions though:
>
> Regarding ActionDispatcher -
> * The ParameterListActionDispatcher class isn't in the 1.2.8 struts
> distribution that I downloaded, and is linked as a bugfix. Do I need
> to download the entire struts source, add this in and recompile, or is
> there an easier way?

ParameterListActionDispatcher is a proposal for upcoming Struts
release. The more people use it and find it useful, the more chances
that it will be included. So, try it and vote for it if you like it:
http://issues.apache.org/bugzilla/show_bug.cgi?id=38343 I hope you
will like it, I think it is the best known solution for event dispatch
in Struts.

If you use Struts 1.2.7+, all you need is only
ParameterListActionDispatcher class. Download it and compile it along
with your project. If you use older Struts version than you will need
base ActionDispatcher as well, but nothing more.

> Regarding DataEntryForm -
> * In sections 6 & 7 it describes a class
> ParameterMappingDispatchAction that I also don't see in the
> distribution (nor in the javadocs online). Is this referring to the
> ParameterListActionDispatcher class or something else? Conceptually it
> seems to be describing the same thing. If not is there an example of
> what step 7 is describing?

Right, I have to fix that. ParameterMappingDispatchAction was an
initial patch, then Paul went with ParameterListActionDispatcher which
is better because you can use any Action class, you do not have to
derive your Action from some other dispatch class anymore. So
disregard ParameterMappingDispatchAction, I will fix the wiki page
later.

> All that aside, when I turn off automatic validation, can I still call
> the validation manually in my action code? ie. Something like :
>
> ActionErrors errors = form.validate(mapping, request);
> if (!errors.isEmpty()) {
>     // determine which forward key to use based upon which step I am
> in the process
>     forward = mapping.findForward(forwardKey);
>     saveErrors(request, errors);
>     return forward;
> }

Of course. This is exactly how you do it, perfect.

> Is there anything else I need to do to validate the form manually?

No. You may want to check errors for null, but it depends on how you
implemented validate() method.

Michael.

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


Re: multiple-step form processing

Posted by Chris Cheshire <ch...@gmail.com>.
Thanks Michael, both of those are helpful.

I have a few extra questions though:

Regarding ActionDispatcher -
* The ParameterListActionDispatcher class isn't in the 1.2.8 struts
distribution that I downloaded, and is linked as a bugfix. Do I need
to download the entire struts source, add this in and recompile, or is
there an easier way?

Regarding DataEntryForm -
* In sections 6 & 7 it describes a class
ParameterMappingDispatchAction that I also don't see in the
distribution (nor in the javadocs online). Is this referring to the
ParameterListActionDispatcher class or something else? Conceptually it
seems to be describing the same thing. If not is there an example of
what step 7 is describing?

All that aside, when I turn off automatic validation, can I still call
the validation manually in my action code? ie. Something like :

ActionErrors errors = form.validate(mapping, request);
if (!errors.isEmpty()) {
    // determine which forward key to use based upon which step I am
in the process
    forward = mapping.findForward(forwardKey);
    saveErrors(request, errors);
    return forward;
}

Is there anything else I need to do to validate the form manually?

Thanks

Chris


On 3/2/06, Michael Jouravlev <jm...@gmail.com> wrote:
> On 3/2/06, Chris Cheshire <ch...@gmail.com> wrote:
> > I want to set up a form that is entered over 3 successive pages.
> >
> > I have a single form bean for all of them that includes all of the
> > fields, and the validate method only validates the fields that were
> > implemented on each particular step.
> >
> > Step 2 will present 1 of 2 sub-forms, depending on an option selected
> > on the bottom of form 1 (ie, either enter credit card info, or bank
> > account info).
> >
> > I was thinking of using a DispatchAction to process each step and move
> > to the next part of the form sequence, but my problem is with
> > automatic validation and the struts-config declarations. I can only
> > declare one input per action, so if validation fails on any step the
> > controller would always redirect back to that specified input page  -
> > which might not be the one the user was on.
> >
> > Do I actually need to set up multiple actions each with their own
> > input and process the steps through there or is there a way I can do
> > this with a single DispatchAction?
> >
> > Or better yet, can I set validation to false in struts-config and then
> > call the validation routine myself inside the action and then forward
> > back to the correct input page if it fails?
>
> Do not use automatic validation, it prevents your action class from
> being called if validation fails. See these pages for a start:
> http://wiki.apache.org/struts/ActionDispatcher
> http://wiki.apache.org/struts/DataEntryForm
>
> Michael.

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


Re: multiple-step form processing

Posted by Michael Jouravlev <jm...@gmail.com>.
On 3/2/06, Chris Cheshire <ch...@gmail.com> wrote:
> I want to set up a form that is entered over 3 successive pages.
>
> I have a single form bean for all of them that includes all of the
> fields, and the validate method only validates the fields that were
> implemented on each particular step.
>
> Step 2 will present 1 of 2 sub-forms, depending on an option selected
> on the bottom of form 1 (ie, either enter credit card info, or bank
> account info).
>
> I was thinking of using a DispatchAction to process each step and move
> to the next part of the form sequence, but my problem is with
> automatic validation and the struts-config declarations. I can only
> declare one input per action, so if validation fails on any step the
> controller would always redirect back to that specified input page  -
> which might not be the one the user was on.
>
> Do I actually need to set up multiple actions each with their own
> input and process the steps through there or is there a way I can do
> this with a single DispatchAction?
>
> Or better yet, can I set validation to false in struts-config and then
> call the validation routine myself inside the action and then forward
> back to the correct input page if it fails?

Do not use automatic validation, it prevents your action class from
being called if validation fails. See these pages for a start:
http://wiki.apache.org/struts/ActionDispatcher
http://wiki.apache.org/struts/DataEntryForm

Michael.

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