OK, let's try the inline approach; patch follows:
Index: validator/src/example/org/apache/commons/validator/example/ValidateExample.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/validator/src/example/org/apache/commons/validator/example/ValidateExample.java,v retrieving revision 1.10 diff -u -r1.10 ValidateExample.java --- validator/src/example/org/apache/commons/validator/example/ValidateExample.java 25 May 2003 18:00:24 -0000 1.10 +++ validator/src/example/org/apache/commons/validator/example/ValidateExample.java 26 May 2003 21:21:00 -0000 @@ -159,6 +159,16 @@ bean.setAge("Too Old"); results = validator.validate(); printResults(bean, results, resources); + + // Now we will turn on success-result filtering + // and re-run the same test + validator.setOnlyErrorFlag(true); + results = validator.validate(); + printResults(bean, results, resources); + System.out.println("(contrast this with the report above)"); + + // Turn off success-result filtering for the final test + validator.setOnlyErrorFlag(false); // Now everything should pass. bean.setAge("123"); Index: validator/src/share/org/apache/commons/validator/Validator.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/validator/src/share/org/apache/commons/validator/Validator.java,v retrieving revision 1.23 diff -u -r1.23 Validator.java --- validator/src/share/org/apache/commons/validator/Validator.java 24 May 2003 20:09:39 -0000 1.23 +++ validator/src/share/org/apache/commons/validator/Validator.java 26 May 2003 21:21:00 -0000 @@ -168,6 +168,12 @@ protected boolean useContextClassLoader = false; /** + * Whether or not to report only error results + * when validating. Default is <code>false</code>. + */ + protected boolean onlyErrors = false; + + /** * Construct a <code>Validator</code> that will * use the <code>ValidatorResources</code> * passed in to retrieve pluggable validators @@ -194,6 +200,22 @@ } /** + * Construct a <code>Validator</code> that will + * use the <code>ValidatorResources</code> + * passed in to retrieve pluggable validators + * the different sets of validation rules. + * + * @param resources <code>ValidatorResources</code> to use during validation. + * @param formName Key used for retrieving the set of validation rules. + * @param reportOnlyErrors Flag to turn off collecting success results. + */ + public Validator(ValidatorResources resources, String formName, boolean reportOnlyErrors) { + this.resources = resources; + this.formName = formName; + this.onlyErrors = reportOnlyErrors; + } + + /** * Add a resource to be used during the processing * of validations. * @@ -258,6 +280,20 @@ } /** + * Gets the current value of the flag to suppress success reporting. + */ + public boolean getOnlyErrorFlag() { + return onlyErrors; + } + + /** + * Sets the current value of the flag to suppress success reporting. + */ + public void setOnlyErrorFlag(boolean reportOnlyErrors) { + this.onlyErrors = reportOnlyErrors; + } + + /** * Gets the page. This in conjunction with the page property of * a <code>Field<code> can control the processing of fields. If the field's * page is less than or equal to this page value, it will be processed. @@ -461,7 +497,9 @@ Object result = validationMethod.invoke(va.getClassnameInstance(), paramValue); - results.add(field, va.getName(), isValid(result), result); + if(!onlyErrors || (onlyErrors && !isValid(result))) { + results.add(field, va.getName(), isValid(result), result); + } if (!this.isValid(result)) { return false;