You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Sobkowski, Andrej" <An...@emergis.com> on 2001/12/06 23:22:14 UTC

Struts Validator (dumb?) question

Hello All,

I'm trying to use the Struts validator but it doesn't seem to be working in
my - relatively common - case.

I have a modify.jsp page that is displayed upon calling
/modifyAction?command=init (using the DispatchAction). No validation must be
performed at this point. The user then enters some data and submits the form
to /modifyAction?command=update and at this point I clearly want the
validation to be performed. I also have a search page that can be called
with /modifyAction?command=search (no validation, of course).

How can I do this?

I've tried the following:
- myForm extends ValidatorForm and <form name="myForm ...> in
validation.xml. 
This doesn't work as the form is validated on the init method (the blank
modify.jsp is displayed the first time with an error message saying "field
required" as the validation is performed on the form)
- myForm extends ValidatorActionForm and <form name="/modifyAction" ...> in
validation.xml
This doesn't work because when I call the search page with
/modifyAction?command=search, the validation is triggered (it matches
"/modifyAction") and doesn't allow me to go to the search page until the
data is valid (which doesn't really make sense since I want to select
something).

Do you have any suggestions? Is there a way I can do the above with the
Struts validator? Am I structuring my actions in the wrong way? I think I
need a "DispatchValidatorForm"... :)

Thank you for any help.

Andrej


Re: Struts Validator (dumb?) question

Posted by David Winterfeldt <dw...@yahoo.com>.
You either would need to define at least one action
with validate="true" and another with validate="false"
or perform the call to the ActionForm validates method
yourself in the action.  There is an example of using
one action this way in the jdbc example web app that
comes with the Validator.

ActionErrors errors = form.validate(mapping, request);

if (errors == null || errors.empty()) {
   update(request, info);
} else {
   saveErrors(request, errors);
   return (new ActionForward(mapping.getInput()));		
}


David

--- "Sobkowski, Andrej" <An...@emergis.com>
wrote:
> Hello All,
> 
> I'm trying to use the Struts validator but it
> doesn't seem to be working in
> my - relatively common - case.
> 
> I have a modify.jsp page that is displayed upon
> calling
> /modifyAction?command=init (using the
> DispatchAction). No validation must be
> performed at this point. The user then enters some
> data and submits the form
> to /modifyAction?command=update and at this point I
> clearly want the
> validation to be performed. I also have a search
> page that can be called
> with /modifyAction?command=search (no validation, of
> course).
> 
> How can I do this?
> 
> I've tried the following:
> - myForm extends ValidatorForm and <form
> name="myForm ...> in
> validation.xml. 
> This doesn't work as the form is validated on the
> init method (the blank
> modify.jsp is displayed the first time with an error
> message saying "field
> required" as the validation is performed on the
> form)
> - myForm extends ValidatorActionForm and <form
> name="/modifyAction" ...> in
> validation.xml
> This doesn't work because when I call the search
> page with
> /modifyAction?command=search, the validation is
> triggered (it matches
> "/modifyAction") and doesn't allow me to go to the
> search page until the
> data is valid (which doesn't really make sense since
> I want to select
> something).
> 
> Do you have any suggestions? Is there a way I can do
> the above with the
> Struts validator? Am I structuring my actions in the
> wrong way? I think I
> need a "DispatchValidatorForm"... :)
> 
> Thank you for any help.
> 
> Andrej
> 
> 


__________________________________________________
Do You Yahoo!?
Send your FREE holiday greetings online!
http://greetings.yahoo.com

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>