Describing the Validator rules to be used for your HTML form data

The Struts Validator framework comes with a rich set of default validator rules, applicable to a number of business scenarios. These rules are imported into the Stores project in the form of the /WEB-INF/validator-rules.xml file that you specified in the Validator plug-in declaration previously. In this step, you examine the contents of the validator-rules.xml file. You then describe which validator rules are used for which fields of your HTML form and how. To do so, you must create the /WEB-INF/validation.xml file that you specified in the Validator plug-in declaration in an earlier step:

Procedure

  1. In the Enterprise Explorer view , expand Stores > WebContent > WEB-INF.
  2. Double-click the validator-rules.xmlfile to open it.
  3. Examine the file contents and note the following information in particular:
    • The introductory comment, which contains the default error messages that are associated with each validator rule defined.
    • The required and email validation rules that are defined with validator elements near the top and the bottom of the file. You will use these rules in your implementation.
  4. Keep the file open, as you require it in a subsequent step.
  5. Back in the Enterprise Explorer view, expand Stores > WebContent > WEB-INF.
  6. Double-click the validation.xml file to open it.
  7. Examine the file contents and note the following information 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 the mapping 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.
  8. Save your changes.