commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Daniel Miller <>
Subject [PATCH] Commons Validator improvements
Date Sat, 16 Apr 2005 16:08:11 GMT
A long time ago I tried sending this to the dev mailing list, but it must have slipped through
the cracks.

The intent of this work is to make Commons Validator easier to integrate into other projects.
These are a the issues that I tried to fix:

1. I think the current FieldChecks in Struts is receiving more information than is needed
(i.e. ActionErrors and HttpServletRequest). Neither of these objects is needed for the actual
validation--they are both used to let the framework know when a validation error occurrs.
Maybe the HttpServletRequest object could be justified because it provides a way for the validation
logic to retrieve dependencies, but most validation logic doesn't need that (or it should
receive it through a more structured means such as dependency injection). There is some confusion
between the task of validating a field and "publishing" the fact that validation failed. The
patches I am submitting are an attempt to separate these tasks--the attached org.apache.commons.validator.integration.ValidationResultPublisher
interface provides a way for Validator users to publish the result of validation for each
field. The user can implement this interface and pass an instance to the validator before
invoking V
alidator.validate(). Dependencies such as HttpServletRequest and ActionErrors can be provided
to the ValidationResultPublisher (if needed) at instantiation time.

2. ValidatorResult does not provide all error information (e.g. the default error message
associated with the ValidatorAction). Consequently, I am forced to pass the Field and ValidatorAction
to my ValidationResultPublisher. Do you think it would be acceptable/helpful to provide a
Resources class like org.springframework.validation.commons.Resources that provides helper
methods for extracting message keys and arguments from Field and ValidatorAction?

I have changed my original "publisher" idea from ErrorPublisher to ValidationResultPublisher.
That way both success and failure can easily be observed by the user if desired. One use case
for this is auditing, which could be very useful to detect that all desired validations are
occurring. I expect most people to simply detect and publish failures, ignoring successful

At this point, FieldChecks (or something like it) no longer needs to worry about framework
specific error handling--it just needs to produce the result of the validation (true or false;
success or failure).

The included patches and interface should be all that is needed to update the current code
base. Let me know if you have any ideas on how it could be refined or improved. I'd be especially
greatful if you could think of a better name than "ValidationResultPublisher"--I can't. If
we can get this committed soon enough, I may be able to get official Commons-Validator support
into Spring 1.1.

Thank you,
Daniel Miller

Ted Husted wrote this under the subject "Re: Commons-Validator for Spring":
> The code is under the Apache License, and so long as you follow its 
> terms, you don't need permission from us or anyone else :)
> In the event there were changes that would make the Commons Validator 
> easier to integrate with Spring or other frameworks, please feel free to 
> submit a patch. (Please also feel free to copy me so that I can be sure 
> to review it.) It is our intent that the Commons Validator be useful to 
> projects aside from Struts.
> The code you have now may have been distributed under the Apache License 
> 1.1, but you may also consider to be under the new 2.0 license, if that 
> were more convenient.  (We are in the process of transitioning.)
> Both Rod and I will be speaking at a conference April 3, and I am 
> looking forward to the opportunity of meeting him.
> -Ted.
> On Fri, 12 Mar 2004 17:42:17 -0500, Daniel Miller wrote:
>> Hello Ted and Craig,
>> My name is Daniel Miller and I have been using Struts for almost a
>> year now. Recently I began to hear about the Spring framework, and
>> after further investigation I decided to use Spring as a
>> lightweight container. Once I got into it, I began to recognize the
>> need for a generic bean validation in Spring. Since I had
>> experience using Struts with the Commons-Validator, I decided to
>> try to make an adaptor for Spring that would give it much of the
>> same validation functionality that Struts has for ActionForms--for
>> any bean. Thanks to the example of the code in
>> org.apache.struts.validator.ValidatorPlugIn, I was able to attain
>> this goal fairly easily.
>> I am writing this letter to ask for your permission to use sections
>> of the code found in the org.apache.struts.validator and
>> org.apache.struts.taglib.html.JavascriptValidatorTag package and
>> class to further extend the functionality of my validator adaptor
>> for Spring. Specifically, I would like to modify the code found in
>> FieldChecks, ValidatorPlugin, and JavascriptValidatorTag classes as
>> well as the validator-rules.xml file distributed with Struts.
>> Please feel free to reply with any questions or concerns. Your
>> consent would be greatly appreciated.
>> Thank you,
>> Daniel Miller

View raw message