Listing InvalidValues instead of aborting when checking a class

Description

Hello there,

I'm working in a project where we use hibernate validators a lot. We don't just need to validate one attribute at a time, but also compare two or more attributes of a class. We use a combination of validating the class itself and the attributes, f.e.:

@OurClassValidator
class OurClassBO {
...
@FloatRange ( min = 1, max = 100 )
private Double textLength;
...
}

In the OurClassValidator, it validates several other attributes (that cannot be implemented with a simple validator on the attribute, because they depend on other attributes ). And here's the catch, we still want the attributes that failed to appear in the InvalidValue-list. So we throw an InvalidStateException in the "isValid" method of the OurClassValidator and catch it with the ClassValidator and add all the invalidvalues that were caught to the list of invalid values.

I've attached a patch to the ClassValidator and the ValidateEventListener. I'm horrible at explaining .. I think the code is pretty easy to understand. Err, doing that in every "OurClassValidator" would be a pain, so I wrote a Generic Validator and a lot of magic to call the respecive class validators based on data we transform from Datasources, that are like "tables" in "Smartclient", a JavaScript UI/AJAX etc. library that we use for our frontend ... anyways, my boss wanted the validators in Smartclient to work in Hibernate as well.

Hmm... what else might be important .. hmm... we're not actually modifying the validator source, just extending. I copied the code back into the hibernate validator legacy -repository so it's easier for you guys to apply the patch.

We're going to release this smartclient-to-hibernate-validator package as open source in a while .. it still needs some finetuning, but the general idea is working quite nicely.

Now .. the big question is, is this worth a thought patching the validators to allow the validator-implementations (OurClassValidator, FloatRange) to throw their own invalidstatexception? I'm sure I'm not the only one who faced this problem, but perhaps everyone who really needs this should just extend the ClassValidator and the EventListener like I did? I don't know what's right ... It's the first time ever I send a patch to a project .

keep up the good work!
best regards,
Mark

Environment

Hibernate 3.3.1, Hibernate Validators 3.1.0.CR2

Activity

Show:
Hardy Ferentschik
February 12, 2009, 3:15 PM

Moved issue into legacy component. This issue applies to codebase prior 4.x

Assignee

Unassigned

Reporter

Mark Schmitt

Labels

None

Feedback Requested

None

Feedback Requested By

None

backPortable

None

Suitable for new contributors

None

Pull Request

None

backportDecision

None

backportReEvaluate

None

Priority

Minor
Configure