You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Langdon Stevenson <ls...@objectpositive.com> on 2004/09/04 10:05:48 UTC
Validating single fields in multi-page forms
Hi
I have a multi-page form (about 8 pages total) that take just a few
fields per page that I am implementing in Struts (this is my first
Struts project).
I have succeeded in setting up and implementing validation using the
Validator Framework. Each page passes a "page" number and all
validation rules with that page number or less are triggered on each
submission.
Here in lies my problem. As the form has many steps I would like to be
able to validate only the fields present on a particular page. After
all the previously collected data is being held on the server side.
My understanding of the Validator Framework is that it executes any
validation rule that has a page number that matches or is less than the
current page number.
I have scoured the Validator Framework for a means of limiting the
validator to only executing validation rules for the current page number
but cannot see that option.
My work around is to pass the accumulated data back and forth in hidden
fields. Its not elegant and makes the forms harder to maintain. And if
some data become corrupted from all the extra handling, then the user
would be presented with validation exceptions that made no sense in
their current context.
I really want to user the Validator Framework as it will save me a huge
amount of time and grief. I don't want to code individual validation
rules in the ActionForm.
Is there a way to force this behavior of only running the validations
for a specific page?
Any assistance would be greatly appreciated.
Regards,
Langdon
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Validating single fields in multi-page forms
Posted by Bill Siggelkow <bi...@bellsouth.net>.
Well, if I recall from your original post you only wanted to validate
the fields on the current page only. Validator provides support for a
page attribute that you can use for wizard-style forms. Validator will
use that attribute to validate form fields on the current page and any
previous pages. The reason it does the previous page is primarily for
security since you cannot guarantee that form properties were set from
the intended page.
- Bill Siggelkow
Langdon Stevenson wrote:
> Hi Bill
>
> Thanks for your suggestion. I have switched to ValidatorActionForm for
> my validation and now get the desired result (validation of only the
> fields that appear on the specific page). So problem solved!
>
> I am curious though about your interpretation of "wizard style". The
> form is indeed wizard like, would you do things differently because of
> that?
>
> Langdon
>
>
> Bill Siggelkow wrote:
>
>> If I understand you correctly, you are using a form for multiple-pages
>> but not in a wizard fashion. The best way to do this is to use
>> path-mapping for validator -- in this case your form extends
>> ValidatorActionForm (or DynaValidatorActionForm) and you specify the
>> path to the action for the form name in the validation.xml ...
>>
>> <form name="/Foo/Bar">
>>
>> ... for this action, only these fields will be validated...
>>
>> </form>
>>
>> Bill Siggelkow
>>
>> Langdon Stevenson wrote:
>>
>>> Hi
>>>
>>> I have a multi-page form (about 8 pages total) that take just a few
>>> fields per page that I am implementing in Struts (this is my first
>>> Struts project).
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Validating single fields in multi-page forms
Posted by Langdon Stevenson <ls...@objectpositive.com>.
Hi Bill
Thanks for your suggestion. I have switched to ValidatorActionForm for
my validation and now get the desired result (validation of only the
fields that appear on the specific page). So problem solved!
I am curious though about your interpretation of "wizard style". The
form is indeed wizard like, would you do things differently because of that?
Langdon
Bill Siggelkow wrote:
> If I understand you correctly, you are using a form for multiple-pages
> but not in a wizard fashion. The best way to do this is to use
> path-mapping for validator -- in this case your form extends
> ValidatorActionForm (or DynaValidatorActionForm) and you specify the
> path to the action for the form name in the validation.xml ...
>
> <form name="/Foo/Bar">
>
> ... for this action, only these fields will be validated...
>
> </form>
>
> Bill Siggelkow
>
> Langdon Stevenson wrote:
>
>> Hi
>>
>> I have a multi-page form (about 8 pages total) that take just a few
>> fields per page that I am implementing in Struts (this is my first
>> Struts project).
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Validating single fields in multi-page forms
Posted by Bill Siggelkow <bi...@bellsouth.net>.
If I understand you correctly, you are using a form for multiple-pages
but not in a wizard fashion. The best way to do this is to use
path-mapping for validator -- in this case your form extends
ValidatorActionForm (or DynaValidatorActionForm) and you specify the
path to the action for the form name in the validation.xml ...
<form name="/Foo/Bar">
... for this action, only these fields will be validated...
</form>
Bill Siggelkow
Langdon Stevenson wrote:
> Hi
>
> I have a multi-page form (about 8 pages total) that take just a few
> fields per page that I am implementing in Struts (this is my first
> Struts project).
>
> I have succeeded in setting up and implementing validation using the
> Validator Framework. Each page passes a "page" number and all
> validation rules with that page number or less are triggered on each
> submission.
>
> Here in lies my problem. As the form has many steps I would like to be
> able to validate only the fields present on a particular page. After
> all the previously collected data is being held on the server side.
>
> My understanding of the Validator Framework is that it executes any
> validation rule that has a page number that matches or is less than the
> current page number.
>
> I have scoured the Validator Framework for a means of limiting the
> validator to only executing validation rules for the current page number
> but cannot see that option.
>
> My work around is to pass the accumulated data back and forth in hidden
> fields. Its not elegant and makes the forms harder to maintain. And if
> some data become corrupted from all the extra handling, then the user
> would be presented with validation exceptions that made no sense in
> their current context.
>
> I really want to user the Validator Framework as it will save me a huge
> amount of time and grief. I don't want to code individual validation
> rules in the ActionForm.
>
> Is there a way to force this behavior of only running the validations
> for a specific page?
>
> Any assistance would be greatly appreciated.
>
> Regards,
> Langdon
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org