Hello, All the Validator examples that I have seen seem to be tightly couples with Struts. For instance, most validateXXX(...) methods takes the following types as parameters: Object ValidatorAction Field ActionErrors HttpServletRequest
Because of presence of ActionErrors, this is tightly coupled to Struts. What happens when one day we decide to replace Struts with XYZ? We have to rewrite a piece of this Validator. Because of presence of HttpServletRequest, thi is usable only in the Web App context. What happens if we want to use this Validator in a desktop application? I am wondering how one would create a custom Validator that did not have these 2 dependencies (or at least not the Struts dependency). If I write a custom Validator with a method such as: validateXXX(Object, Field) How do I use this method in a Struts application without passing it instances Struts-specific classes, such as ActionErrors, and still somehow end up with error messages suitable for showing to the user, etc.? I have seen code such as the following, but this would require that a developers manually inserts error messages into an instance of ActionErrors, etc. Is there no better way? ValidatorResources resources = new ValidatorResources(); InputStream rules = ValidateExample.class.getResourceAsStream("validator-rules.xml"); ValidatorResourcesInitializer.initialize(resources, in); InputStream forms = ValidateExample.class.getResourceAsStream("validation.xml"); ValidatorResourcesInitializer.initialize(resources, forms); // Suppose we already had a CheckoutForm object created and populated CheckoutForm form = new CheckoutForm(); // Create a validator with the checkoutForm Validator validator = new Validator(resources, "checkoutForm"); // Tell the validator which bean to validate against. validator.addResource(Validator.BEAN_KEY, form); // Validate the checkoutForm object and store the validation results ValidatorResults results = validator.validate(); Thanks. Otis ________________________________________________ Get your own "800" number Voicemail, fax, email, and a lot more http://www.ureach.com/reg/tag --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]