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
- In the Enterprise Explorer view ,
expand .
- Double-click the validator-rules.xmlfile
to open it.
- 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.
- Keep the file open, as you require it in a subsequent step.
- Back in the Enterprise Explorer view,
expand .
- Double-click the validation.xml file to open it.
- 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:
- It specifies an additional rule, email,
to be used after the required rule is satisfied.
- The msg element for the required rule references an existing consumer
direct store error message.
- Save your changes.