Reputation: 3272
Using the ValidateForm
from Struts 1, we will be able to validate the FORM used in the Struts,
I went through number of links (https://cwe.mitre.org/data/definitions/103.html) still not able to figure the functionality of super.validate()
method in Struts
Default Validation (using super.validate()
in Struts):
public class RegistrationForm extends org.apache.struts.validator.ValidatorForm {
// private variables for registration form
private String name;
private String email;
...
public RegistrationForm() {
super();
}
public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
ActionErrors errors = super.validate(mapping, request);
if (errors == null) {
errors = new ActionErrors();
}
return errors;
}
// getter and setter methods for private variables
}
In the above code what is the significance of super.validate()
method, What is the validation does it perform? Could someone explain this please!
Upvotes: 0
Views: 543
Reputation: 1
It performs validation of request parameters according to the rules defined in validation.xml
. It provides the basic validation and if you want to use a custom validation then you should override its validate()
method. Here's the description of the method:
Validate the properties that have been set from this HTTP request, and return an
ActionErrors
object that encapsulates any validation errors that have been found. If no errors are found, returnnull
or anActionErrors
object with no recorded error messages.
What happens if you override validate()
and not calling super.validate()
:
It will cancel the Struts validation if you override the validate method and not call the
super.validate(mapping, request)
. Do it in your code to coexist the custom validation throughvalidate()
method and framework validation viavalidation.xml
.
Upvotes: 0