Presentation is loading. Please wait.

Presentation is loading. Please wait.

Struts2 Validation using XML Approach. May 12, 2011 Need For Validation Validation can be defined as the assessment of an action so as to ensure that.

Similar presentations


Presentation on theme: "Struts2 Validation using XML Approach. May 12, 2011 Need For Validation Validation can be defined as the assessment of an action so as to ensure that."— Presentation transcript:

1 Struts2 Validation using XML Approach

2 May 12, 2011 Need For Validation Validation can be defined as the assessment of an action so as to ensure that the results obtained are correct, accurate and complete. To avoid the wrong values, we need to perform validation on forms where user submits some values. For example, if user writes his/her email id as abc, we need to give error message to the user that the given email id is not correct. So that we can have only valuable information. Hence validation is necessary.

3 May 12, 2011 Validation using xml To validate a user's form field entries we can use a separate XML file that contains the validation rules. The XML file that contains the validation rules must be named as ActionClassName-validation.xml. Suppose the name of the action calss is Employee.java then the conventional name of the xml file will be Employee-Validation.xml. By using the XML validation file, we can make use of the built-in validators in the Struts 2 framework. This allows the separation of the validation from the application code.

4 May 12, 2011 Some Built-In Validators REQUIRED FIELD VALIDATOR <!DOCTYPE validators PUBLIC "-//Apache Struts//XWork Validator 1.0.3//EN" "http://struts.apache.org/dtds/xwork-validator-1.0.3.dtd"> username must not be null

5 May 12, 2011 EMAIL VALIDATOR Must provide a valid email

6 May 12, 2011 INT VALIDATOR 5 50 Age needs to be between ${min} and ${max}

7 May 12, 2011  1. The field element contains the name of the form property that needs to be validated. 2. The field-validator element inside the field element contains the type of validation that needs to be performed. 3. The error message is displayed using the message element or you can use the properties file to define all the error messages and use the key attribute to specify the error key.  4. The properties file should also have the same name as the Action class.

8 Thank You


Download ppt "Struts2 Validation using XML Approach. May 12, 2011 Need For Validation Validation can be defined as the assessment of an action so as to ensure that."

Similar presentations


Ads by Google