You have seen how easy it is to write user input validation rules in actions forms. Struts goes the extra mile to make input validation even easier by providing the Validator plugin. Using this plugin, you do not even have to write Java code to validate user input. On top of that, the Validator plugin caters for client side validation, dynamic action forms, multipage forms, and custom validators. This is a boon to Struts developers because this means more rapid development. This chapter discusses the benefits of this plugin and explains how to use and extend it.
With the Validator plugin, you write validation rules instead of Java code. Validator comes bundled with default validators that are sufficient for most applications. If you have a specific need, you can extend your action form to handle action form’s properties that need special validating, and at the same time let Validator handle the rest. Alternatively, if the specific validation is required by other parts of your application, you can write it into a validator and plug it into Validator.
This chapter covers the Validator plugin in minute detail by featuring eight sample applications. It starts by introducing and giving you the first taste of the plugin. It then discusses the default validators included in the Validator plugin and the format of validation files. The last sections teach you how to write custom validators and the most complex of the default validators, validwhen.