Tutorials > Program model > Use Struts tags, action forms, and validation

< Previous | Next >


Describe the Validator rules to be used for the HTML form data

The Struts Validator framework comes with a set of default validator rules, applicable to a number of business scenarios.

These rules have been imported for you into the Stores project in the form of the file...

/WEB-INF/validator-rules.xml

...specified in the Validator plug-in declaration in the previous step.

You will then describe which validator rules should be used for which fields of the HTML form and how.

To do so, we will create the file...

/WEB-INF/validation.xml

...specified in the Validator plug-in declaration in an earlier step.


Procedure

  1. In the Enterprise Explorer view, open...

    Stores | WebContent | WEB-INF | validator-rules.xml

  2. Examine the file contents noting the following in particular:

    • The introductory comment, which contains the default error messages associated with each validator rule defined.

    • The required and email validation rules, defined by means of validator elements near the top and the bottom of the file, respectively, which we will use in the implementation.

  3. Keep the file open, as we will need it in a subsequent step.

  4. Back in the Enterprise Explorer view, open...

    Stores | WebContent | WEB-INF | validation.xml

  5. Examine the file contents noting the following in particular:

    • The name attribute of the form element identifies the HTML form to be validated through its associated action form.

    • The field element specifies the rule or rules to be used for a particular field of the form along with the key for the validation error message to be displayed.

    • The mapping for the comment field is similar to that for the name field.

    • The mapping for the email field differs in two respects:

      1. It specifies an additional rule, email, to be used after the required rule is satisfied.

      2. The msg element for the required rule references an existing consumer direct store error message. You will examine its definition in a subsequent step.

  6. Save the changes.

< Previous | Next >


+

Search Tips   |   Advanced Search