Using the Validator Outside of Struts

Although the Validator was originally designed to work with the Struts framework, it can be used to perform generic validation on any JavaBean. There are several steps that must be performed before the framework can be used outside of Struts.

Although the Validator is not dependent on the Struts framework, a considerable amount of work has been done inside of Struts to make it easier to use the Validator. This behavior will need to be replicated for your application if you plan to use the Validator without Struts.


The package dependencies are exactly the same for Struts and non-Struts applications. The ORO, Commons Logging, Commons BeanUtils, Commons Collections, and Digester packages are all required. You will also need an XML parser that conforms to the SAX 2.0 specification. You will not need to include the Struts framework, however.

Functions for loading and initializing the XML Validator resources are the first behaviors to replicate. These are the two XML files that are used to configure the rules for the Validator. When the Validator framework is used in conjunction with Struts, the org.apache.struts.Validator.ValidatorPlugIn class performs this duty. However, because the ValidatorPlugIn is dependent on Struts, you will need to create an alternate approach for initializing the appropriate Validator resources. To do this, you can create a simple Java class that performs the same behavior as the ValidatorPlugIn but doesn’t have a dependency ...

Get Programming Jakarta Struts, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.