CodesJava

Easy learning with example program codes

Struts 2 validation by built-in validators


Struts 2 validation framework provides many generic built-in validators to perform various validations like email validation, required validation, stringlength validation etc. These validations are also known as XML based validation. Built-in validators are placed in an xml file. The name of the xml file should be like actionClassName-validation.xml.

Note: No need to specify any validate() method in the action class.

Types of validators in struts 2.

  1. Field Validators.
  2. Non-field validators.

1. Field validators:

These validators act or perform validations on the single field i.e. field validators are not generic they are specific to the single field. More than one validator can be applied to one field.

Syntax:

<validators>  
  <field name="fieldName">  
    <field-validator type="validatorName">  
      <message>message string</message>  
    </field-validator>  
  </field>  
</validators>

2. Non-field validators:

These validators are the action level validators. Single validator can be applied to multiple fields.

Note: In this approach only one validator can be applied to a single field.

Syntax:

<validators>  
  <validator type=" validatorName ">  
    <param name="fieldName">username</param>  
    <message> message string </message>  
  </validator>  
</validators>

 
Next Topic: Struts 2 required validator with example.
Previous Topic: Struts 2 validation framework with example.

Related Topics:

Struts 2 validation by built-in validators with example.
Struts 2 required validator with example.
Struts 2 requiredstring validator with example.
Struts 2 stringlength validator with example.
Struts 2 int validator with example.
Struts 2 double validator with example.
Struts 2 date validator with example.
Struts 2 email validator with example.
Struts 2 regex validator with example.
Struts 2 url validator with example.

 



Industrial Training

We offers Placement Oriented Training on Java, Spring, JSF, Hibernate, PHP, AngularJS, Angular 4, PLSQL, Oracle BI Publisher etc. We also provides Online training, please mail us at hr@codesjava.com.

Development

We also provides the Development services for Website Development , Java Development, PHP Development, Android App Development etc. You can contact us on hr@codesjava.com.

Copyright © 2019 CodesJava DMCA.com Protection Status SiteMap Reference: Java Wiki