[seam-dev] Seam Validation

Gunnar Morling gunnar.morling at googlemail.com
Tue Mar 8 18:11:58 EST 2011


Hi Emmanuel,

I had initially considered this, too, but then went for the
current approach for two reasons:

* in a Java EE environment default Validator and ValidatorFactory are
provided (and also registered in JNDI etc.) by the container and I don't
think there is a way for Seam Validation kicking in and setting the
constraint validator factory. So I think in EE specifying the factory in
validation.xml is the only way to go.

* in a non-EE environment Seam Validation itself creates and registers
default Validator and ValidatorFactory, so we generally could set the
constraint validator factory here. But a user actually could want to use
another one by specifying it in validation.xml which we then would have to
override. In this case it might be unexpected by the user that the factory
in use is another one than defined in validation.xml.

So at least for now sticking with validation.xml seems like the best choice
to me.

We might re-visit this later on (at least for the non-EE case, there we
could give validation.xml precedence and set the injecting factory only, if
no other one was given via XML), but to keep things simple I'd like to
follow the current approach for Seam 3. I created
https://issues.jboss.org/browse/SEAMVALIDATE-10 for this, which we can
address in a future release.

Of course a user could always create a custom qualifier annotation and a
producer, which creates a Validator(Factory) in the way you describe,
rendering validation.xml unnecessary.

Gunnar


2011/3/8 Emmanuel Bernard <emmanuel at hibernate.org>

> Hi Gunnar,
> I was reading your doc on Seam Validation
>
> http://docs.jboss.org/seam/3/validation/latest/reference/en-US/html_single/#d0e146
>
> I was thinking that we might be able to go one step further with the
> "Dependency injection for constraint validators".
> Today you ask people to configure the ConstraintValidatorFactory using some
> XML snippet. How about Seam transparently configure it.
>
> You can do it programmatically at two levels:
>
> 1. during the construction of ValidatorFactory
> ValidatorFactory factory = Validation
>       .byDefaultProvider().configure()
>          .constraintValidatorFactory( new
> InjectingConstraintValidatorFactory() )
>          .buildValidatorFactory();
>
> 2. or during the Validator construction
> validator
>    .usingContext()
>        .constraintValidatorFactory( new
> InjectingConstraintValidatorFactory() )
>    .getValidator();
>
> WDYT?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/seam-dev/attachments/20110309/82892d6c/attachment-0001.html 


More information about the seam-dev mailing list