Coder
Coder

Reputation: 3272

ValidateForm class in Struts 1.X

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

Answers (1)

Roman C
Roman C

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, return null or an ActionErrors 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 through validate() method and framework validation via validation.xml.

Upvotes: 0

Related Questions