Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Info

The example code for this tutorial, Formform_XML_Validation_Struts2_Ant or Form_XML_Validation_Struts2_Mvn, is available on Google Code - httpxml_validation, is available for checkout at https://codesvn.google.com/p/struts2-examples/downloads/listImage Removed. After downloading and unzipping the file, you'll have a folder named Form_XML_Validation_Struts2_Ant (or Form_XML_Validation_Struts2_Mvn). In that folder will be a README.txt file with instructions on now to build and run the example application.apache.org/repos/asf/struts/sandbox/trunk/struts2examples/Image Added

Introduction

In this tutorial we'll cover how to validate a user's input in form fields using Struts 2's XML validation methodology. In the Form Validation tutorial we discussed validating a user's input using the validate method in the Action class. Using a separate XML validation file gives you the ability to use validators built-in to the Struts 2 framework.

...

The example application that supports this tutorial (Form_XML_Validation_Struts2 available at http://code.google.com/p/struts2-examples/downloads/listImage Removed.) shows how to use Struts 2's XML validation methodology. The information that can be edited is encapsulated in an object of class Person.

...

To validate a user's form field entries you can use a separate XML file that contains your validation rules. The XML file that contains the validation rules must be named as ActionClassName-validation.xml. In the example application, the XML validation file is named EditAction-validation.xml (see src/main/resources/org/apache/struts/edit/action for the Maven example or src/org/apache/struts/edit/action for the Ant example).

Struts 2 provides several different validators that you can use in the XML validation file. See Validation for a list of validators you can employ.

...