You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Matheus Eduardo Machado Moreira <ma...@gmail.com> on 2006/01/13 14:08:43 UTC
Validation per action
Hi everybody,
is there any way to configure the validation mechanism per action
instead than per form? And is it possible to configure this mechanism
per use case (not a global configuration)?
The project's architect decided that each use case (that includes
all the crud operations) should have just one Form class because it
would be easier to share information between the use case's
interfaces. We have interfaces with an odd layout - they present the
search form and the edit form together. This generates the following
situations concerning validation:
1. When the user press the search button, the edition fields must not
be validated.
2. When the user press other button related to edition, the search
fields (parameters) must not be validated.
We don't know how to control the validation mechanism to indicate
when each validation must occur. We tried to use the multipage
validation (search part is page 1, edit part is page 2) but it doesn't
work.
Does anyone know how to solve this problem? Thanks in advance.
Matheus Eduardo
Belo Horizonte / MG / Brazil
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Validation per action
Posted by Laurie Harper <la...@holoweb.net>.
Rick Reumann wrote:
> Sony Thomas wrote the following on 1/13/2006 8:34 AM:
>
>> 1. You can set the validate attribute to false in struts-config and
>> then in the action you can call the validate method.
>>
>> inside the action
>
> This is the approach I like to use:
> http://www.learntechnology.net/validate-manually.do (bottom of article
> shows technique),
>
> but, if you don't want to call validate manually from your Action (which
> again I recommend:), you could just use an instance of
> ValidatorActionForm...
>
> http://struts.apache.org/struts-taglib/dev_validator.html
> "An alternative approach is to use the action mapping path attribute. In
> this case, you extend the ValidatorActionForm instead of the
> ValidatorForm. The ValidatorActionForm uses the action element's path
> attribute from the Struts configuration which should match the form
> element's name attribute in the Validator configuration."
Yep, that'll get you the validation based on the action rather than the
form. To handle the requirement that you have two distinct sets of
validation for the same form/action [search validation and edit
validation], take a look at the validwhen validator rule [1].
An alternative, if you can use it in your application, would be to have
two forms on the page, one for the search and one for the edit. If you
can split your forms in two like that, validation will be a lot easier
to deal with.
HTH,
L.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Validation per action
Posted by Rick Reumann <st...@reumann.net>.
Sony Thomas wrote the following on 1/13/2006 8:34 AM:
> 1. You can set the validate attribute to false in struts-config and then
> in the action you can call the validate method.
>
> inside the action
This is the approach I like to use:
http://www.learntechnology.net/validate-manually.do (bottom of article
shows technique),
but, if you don't want to call validate manually from your Action (which
again I recommend:), you could just use an instance of
ValidatorActionForm...
http://struts.apache.org/struts-taglib/dev_validator.html
"An alternative approach is to use the action mapping path attribute. In
this case, you extend the ValidatorActionForm instead of the
ValidatorForm. The ValidatorActionForm uses the action element's path
attribute from the Struts configuration which should match the form
element's name attribute in the Validator configuration."
--
Rick
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Validation per action
Posted by Sony Thomas <so...@genialgenetics.com>.
Hi,
you can solve this problem two three ways.
1. You can set the validate attribute to false in struts-config and then
in the action you can call the validate method.
inside the action
either by : form.validate(request,mapping)
or by : suppose it is UserForm
UserForm userForm = (UserForm)form;
form.validate(request,mapping);
2. set a hidden property in the jsp page
<html:hidden property="add" value="add"/>
check this in the form inside validate method and if it is add then do
the validation or edit do not go for validation
hope this solve your problem. any doubt let me know
sony
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org