Friday, November 13, 2009

bean-validation constraint validators and dependency injection support in jsf

myfaces extval allows to use beans as validators. so it's possible to inject services into validators. bean-validation (jsr 303) specifies that the class of a validator has to be defined hardcoded. anyway, via the ConstraintValidatorFactory it's possible to change the default behavior.

in jsf you can query beans by name (not by type which is possible e.g. in spring). extval allows to provide a custom implementation of the ValidatorFactory. so you can optimize the lookup for your dependency management container (e.g. to make it typesafe).

anyway, out of the box the bv-integration module of extval (the next milestone of it) allows to provide/override constraint-validators via bean(s).
a detailed description is available at EXTVAL-70.

a spring bean for the example mentioned in EXTVAL-70 would be:

<bean id="customConstraintValidator">
<property name="customService" ref="...">