You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Glenn Holmer <gh...@weycogroup.com> on 2003/10/07 13:49:22 UTC

DynaValidatorForm

When you're using DynaValidatorForm and the page has two buttons
(e.g. "Commit" and "Cancel"), how do you not validate if the user
hits the "Cancel" button (which on my page, also submits, but the
action checks the value of the submit button)?

Do I have to write a Form subclass to do this?  Can you have a
hand-coded Form subclass and use the Validator rules as well?

-- 
____________________________________________________________
Glenn Holmer                          gholmer@weycogroup.com
Programmer/Analyst                       phone: 414.908.1809
Weyco Group, Inc.                          fax: 414.908.1601


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


Re: DynaValidatorForm

Posted by Frederic Dernbach <fr...@free.fr>.
Instead of 
if (errors.size() > 0) {
	request.setAttribute("org.apache.struts.action.ERROR", errors);
	forward = "failure";
}

I would write :
if (! errors.isEmpty()) {
	saveErrors(request, errors);
	forward="failure";
}

Le mar 07/10/2003 à 16:27, Glenn Holmer a écrit :
> Frederic Dernbach wrote:
> > Glenn,
> > 
> > - Use a descendant of DispatchAction for your form's action,
> > - Have two separate methods in the action class for your two buttons
> > (one for 'commit' and one for 'cancel').
> > - In the struts-config.xml file, specify attribute 'validate' to 'false'
> > for your form's action.The form validation wont't happen automatically
> > this way.
> > - In the method for the 'commit' button, call explicitely 'validate' on
> > your form. But not in the method associated to the cancel button.
> 
> Thanks, I got that to work without resorting to a DispatchAction
> like this:
> 
>      if (confirm.equals(cancel)) {
>        forward = "complete";
>      } else {
>        errors = dynaForm.validate(mapping, request);
>        if (errors.size() > 0) {
>          request.setAttribute("org.apache.struts.action.ERROR", errors);
>          forward = "failure";
>        }
>      }
> 
> Is that the right way to put the errors in play?
> 
> -- 
> ____________________________________________________________
> Glenn Holmer                          gholmer@weycogroup.com
> Programmer/Analyst                       phone: 414.908.1809
> Weyco Group, Inc.                          fax: 414.908.1601
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
> 
> 



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


Re: DynaValidatorForm

Posted by Glenn Holmer <gh...@weycogroup.com>.
Adam Hardy wrote:
> Why get complicated? All you need is <html:cancel/> and the validation 
> will automatically not be executed. Even the javascript validation if 
> you are using DynaValidatorForm.

Now *that* is slick.  Thanks.

-- 
____________________________________________________________
Glenn Holmer                          gholmer@weycogroup.com
Programmer/Analyst                       phone: 414.908.1809
Weyco Group, Inc.                          fax: 414.908.1601


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


Re: DynaValidatorForm

Posted by Frederic Dernbach <fr...@free.fr>.
Adam,

You are right.

I just wrote something more generic.

Le mar 07/10/2003 à 17:00, Adam Hardy a écrit :
> Why get complicated? All you need is <html:cancel/> and the validation 
> will automatically not be executed. Even the javascript validation if 
> you are using DynaValidatorForm.
> 
> Adam
> 
> On 10/07/2003 04:27 PM Glenn Holmer wrote:
> > Frederic Dernbach wrote:
> > 
> >> Glenn,
> >>
> >> - Use a descendant of DispatchAction for your form's action,
> >> - Have two separate methods in the action class for your two buttons
> >> (one for 'commit' and one for 'cancel').
> >> - In the struts-config.xml file, specify attribute 'validate' to 'false'
> >> for your form's action.The form validation wont't happen automatically
> >> this way.
> >> - In the method for the 'commit' button, call explicitely 'validate' on
> >> your form. But not in the method associated to the cancel button.
> > 
> > 
> > Thanks, I got that to work without resorting to a DispatchAction
> > like this:
> > 
> >     if (confirm.equals(cancel)) {
> >       forward = "complete";
> >     } else {
> >       errors = dynaForm.validate(mapping, request);
> >       if (errors.size() > 0) {
> >         request.setAttribute("org.apache.struts.action.ERROR", errors);
> >         forward = "failure";
> >       }
> >     }
> > 
> > Is that the right way to put the errors in play?
> > 
> 
> -- 
> struts 1.1 + tomcat 5.0.12 + java 1.4.2
> Linux 2.4.20 RH9
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
> 
> 



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


Re: DynaValidatorForm

Posted by Adam Hardy <ah...@cyberspaceroad.com>.
Why get complicated? All you need is <html:cancel/> and the validation 
will automatically not be executed. Even the javascript validation if 
you are using DynaValidatorForm.

Adam

On 10/07/2003 04:27 PM Glenn Holmer wrote:
> Frederic Dernbach wrote:
> 
>> Glenn,
>>
>> - Use a descendant of DispatchAction for your form's action,
>> - Have two separate methods in the action class for your two buttons
>> (one for 'commit' and one for 'cancel').
>> - In the struts-config.xml file, specify attribute 'validate' to 'false'
>> for your form's action.The form validation wont't happen automatically
>> this way.
>> - In the method for the 'commit' button, call explicitely 'validate' on
>> your form. But not in the method associated to the cancel button.
> 
> 
> Thanks, I got that to work without resorting to a DispatchAction
> like this:
> 
>     if (confirm.equals(cancel)) {
>       forward = "complete";
>     } else {
>       errors = dynaForm.validate(mapping, request);
>       if (errors.size() > 0) {
>         request.setAttribute("org.apache.struts.action.ERROR", errors);
>         forward = "failure";
>       }
>     }
> 
> Is that the right way to put the errors in play?
> 

-- 
struts 1.1 + tomcat 5.0.12 + java 1.4.2
Linux 2.4.20 RH9


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


Re: DynaValidatorForm

Posted by Glenn Holmer <gh...@weycogroup.com>.
Frederic Dernbach wrote:
> Glenn,
> 
> - Use a descendant of DispatchAction for your form's action,
> - Have two separate methods in the action class for your two buttons
> (one for 'commit' and one for 'cancel').
> - In the struts-config.xml file, specify attribute 'validate' to 'false'
> for your form's action.The form validation wont't happen automatically
> this way.
> - In the method for the 'commit' button, call explicitely 'validate' on
> your form. But not in the method associated to the cancel button.

Thanks, I got that to work without resorting to a DispatchAction
like this:

     if (confirm.equals(cancel)) {
       forward = "complete";
     } else {
       errors = dynaForm.validate(mapping, request);
       if (errors.size() > 0) {
         request.setAttribute("org.apache.struts.action.ERROR", errors);
         forward = "failure";
       }
     }

Is that the right way to put the errors in play?

-- 
____________________________________________________________
Glenn Holmer                          gholmer@weycogroup.com
Programmer/Analyst                       phone: 414.908.1809
Weyco Group, Inc.                          fax: 414.908.1601


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


Re: DynaValidatorForm

Posted by Frederic Dernbach <fr...@free.fr>.
Glenn,

- Use a descendant of DispatchAction for your form's action,
- Have two separate methods in the action class for your two buttons
(one for 'commit' and one for 'cancel').
- In the struts-config.xml file, specify attribute 'validate' to 'false'
for your form's action.The form validation wont't happen automatically
this way.
- In the method for the 'commit' button, call explicitely 'validate' on
your form. But not in the method associated to the cancel button.

Hope this helps.


Le mar 07/10/2003 à 13:49, Glenn Holmer a écrit :
> When you're using DynaValidatorForm and the page has two buttons
> (e.g. "Commit" and "Cancel"), how do you not validate if the user
> hits the "Cancel" button (which on my page, also submits, but the
> action checks the value of the submit button)?
> 
> Do I have to write a Form subclass to do this?  Can you have a
> hand-coded Form subclass and use the Validator rules as well?
> 
> -- 
> ____________________________________________________________
> Glenn Holmer                          gholmer@weycogroup.com
> Programmer/Analyst                       phone: 414.908.1809
> Weyco Group, Inc.                          fax: 414.908.1601
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
> 
> 



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


Re: DynaValidatorForm

Posted by Glenn Holmer <gh...@weycogroup.com>.
Adam Hardy wrote:
> If your buttons have values set then you can test to see which button 
> value was submitted. Even better though with struts you can use the 
> built-in cancel button without needing to do that. <html:cancel/> and 
> then check action.isCancelled(request)

But those would be done in the action class, right?  I'm wondering
if this can be done using a DynaValidatorForm -- the Validator is
tossing me back to the input page before the action is invoked.

>> When you're using DynaValidatorForm and the page has two buttons
>> (e.g. "Commit" and "Cancel"), how do you not validate if the user
>> hits the "Cancel" button (which on my page, also submits, but the
>> action checks the value of the submit button)?
>>
>> Do I have to write a Form subclass to do this?  Can you have a
>> hand-coded Form subclass and use the Validator rules as well?

-- 
____________________________________________________________
Glenn Holmer                          gholmer@weycogroup.com
Programmer/Analyst                       phone: 414.908.1809
Weyco Group, Inc.                          fax: 414.908.1601


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


Re: DynaValidatorForm

Posted by Adam Hardy <ah...@cyberspaceroad.com>.
If your buttons have values set then you can test to see which button 
value was submitted. Even better though with struts you can use the 
built-in cancel button without needing to do that. <html:cancel/> and 
then check action.isCancelled(request)

Adam

On 10/07/2003 01:49 PM Glenn Holmer wrote:
> When you're using DynaValidatorForm and the page has two buttons
> (e.g. "Commit" and "Cancel"), how do you not validate if the user
> hits the "Cancel" button (which on my page, also submits, but the
> action checks the value of the submit button)?
> 
> Do I have to write a Form subclass to do this?  Can you have a
> hand-coded Form subclass and use the Validator rules as well?
> 

-- 
struts 1.1 + tomcat 5.0.12 + java 1.4.2
Linux 2.4.20 RH9


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