0
Using Cancel button in struts
Cancel button is a type of submit button which bypasses validation during submission of the form. So, cancel button can be used for submitting a form without validation and to reset form.
- Using Cancel button for bypassing validation
Reset button is also available in struts but reset button resets to the form fields to default if the form has not been submitted or has not be passed through validator. Once the validation has occured and validation failed, the form fields are populated with the values we have send for validation. Now by pressing reset button will retain the typed and not default values. In this case, struts cancel button is used. Struts cancel button can be rendered through<html:cancel/>.
It is rendered in html as<input type="reset" value="Reset"><input type="submit"
name="org.apache.struts.taglib.html.CANCEL" value="Cancel"
onclick="bCancel=true;">
The onclick="bCancel=true;" in generated reset button plays a great role for bypassing clientside validation.
If you are using dispactch action, create a method called 'cancelled' and get the form field values inside that method.
Cancel button bypassed both serverside and clientside validation. - Using Cancel button as reset button
If you're using Struts 1.2.9 or above, you must specify cancellable="true" in the Action mapping as;<action
now its time to reset form fields through action like;
attribute="registrationForm"
input="..."
...
...
<set-property property="cancellable" value="true"/>
...
...
</action>if(isCancelled(request)){
[I'm using DynaValidatorForm here]
registrationForm.set("firstname",
"");
}
If you are using DispatchAction then you have to create a method named cancelled and reset forms there.