Ensuring that users enter data correctly can make the difference between a production-ready application and one relegated to remain in the Quality Assurance department. Web applications need to verify the data entered is valid. Data validation takes two forms: syntactic and semantic. Syntactic validity indicates the data is in the correct format; for example, making sure that a numeric field contains only numeric digits. Semantic validity indicates the data means what it should in the functional context of the application. For example, if a user enters his or her birthdate, that date can't be in the future.
The recipes in this chapter cover some advanced uses of the Struts
Validator. Some of the recipes use new features of the Validator such
a reusable type of validation. Several recipes show you how easy it
is to create your own validators. Providing locale-specific
validators to support internationalization is covered. If
you're familiar with the Validator, skip ahead to
the particular recipes that interest you.
Struts was designed from the beginning to support validation. Every
ActionForm has a
If a validation check requires access to a back-end business service,
like an EJB or the database, place the call to the business service
Action that processes the form and not the
You can add your own data validation checks for form data ...