XWork : Generic Object Validation
This page last changed on Jun 03, 2004 by unkyaku.
XWork's validation framework is not just limited to Actions. It can be used to validate virtually any object. Once you've set up your validator config file (validators.xml) and your validation rules (ClassName-validation.xml), all it takes are a couple lines of code: String context = null; ValidatorContext context = new DelegatingValidatorContext(objectToValidate); ActionValidatorManager.validate(objectToValidate, null, context); This will cause any errors to be logged (where it gets logged to depends on how commons-logging is configured). Ideally, you would either implement your own ValidatorContext to handle how error messages are logged and evaluated, or have your objects that are to be evaluated implement ValidationAware, TextProvider and/or LocaleProvider.Matthew Payne has a JUnit demo of this at http://www.sutternow.com/index.do?post=51fe0c00fc17aec500fc33f6bb8e006e. |
![]() |
Document generated by Confluence on Dec 12, 2004 12:35 |