You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@myfaces.apache.org by Rudy De Busscher <rd...@gmail.com> on 2010/03/06 20:48:49 UTC

[Extval] BeanAware constraint validators for Model Validation beanValidation

[ExtVal] BeanAware constraint validators for Model Validation beanValidation

Hi,

The Constraint Validator for BeanValidation constraints on properties can be
defined in a context repository. The *
BeanValidationModuleValidationInterceptorInternals.validate* method makes
use of code that checks if a bean is defined in a context that can be used.

The *ModelValidationPhaseListener* makes use of a slightly different aproach
which leads to the fact that no beans could be used.

 A small change to the ModelValidationPhaseListener.validateTarget method
solves this problem.

I haven't tested the fix extensively but with my small test, I was able to
use a bean for the constraint validator defined on a class.


*ModelValidationPhaseListener.validateTarget*


        return ExtValBeanValidationContext.getCurrentInstance()
>                 .getValidatorFactory().usingContext()
>
> .messageInterpolator(ExtValBeanValidationContext.getCurrentInstance().getMessageInterpolator())
>                 .getValidator()
>                 .validate(validationTarget, groups);
>

should become

        ValidatorFactory validatorFactory =
> ExtValBeanValidationContext.getCurrentInstance().getValidatorFactory();
>         return validatorFactory
>                 .usingContext()
>
> .messageInterpolator(ExtValBeanValidationContext.getCurrentInstance().getMessageInterpolator())
>
> .constraintValidatorFactory(validatorFactory.getConstraintValidatorFactory())
>
> .traversableResolver(validatorFactory.getTraversableResolver())
>                 .getValidator()
>                 .validate(validationTarget, groups);
>

See EXTVAL-86 for the patch.

Include it in the x.x.3 release ?

regards
Rudy.

Re: [Extval] BeanAware constraint validators for Model Validation beanValidation

Posted by Gerhard Petracek <ge...@gmail.com>.
thx - i synced both parts - so it will be in r3.

regards,
gerhard

http://www.irian.at

Your JSF powerhouse -
JSF Consulting, Development and
Courses in English and German

Professional Support for Apache MyFaces


2010/3/6 Rudy De Busscher <rd...@gmail.com>

> [ExtVal] BeanAware constraint validators for Model Validation
> beanValidation
>
> Hi,
>
> The Constraint Validator for BeanValidation constraints on properties can
> be defined in a context repository. The *
> BeanValidationModuleValidationInterceptorInternals.validate* method makes
> use of code that checks if a bean is defined in a context that can be used.
>
> The *ModelValidationPhaseListener* makes use of a slightly different
> aproach which leads to the fact that no beans could be used.
>
>  A small change to the ModelValidationPhaseListener.validateTarget method
> solves this problem.
>
> I haven't tested the fix extensively but with my small test, I was able to
> use a bean for the constraint validator defined on a class.
>
>
> *ModelValidationPhaseListener.validateTarget*
>
>
>         return ExtValBeanValidationContext.getCurrentInstance()
>>                 .getValidatorFactory().usingContext()
>>
>> .messageInterpolator(ExtValBeanValidationContext.getCurrentInstance().getMessageInterpolator())
>>                 .getValidator()
>>                 .validate(validationTarget, groups);
>>
>
> should become
>
>         ValidatorFactory validatorFactory =
>> ExtValBeanValidationContext.getCurrentInstance().getValidatorFactory();
>>         return validatorFactory
>>                 .usingContext()
>>
>> .messageInterpolator(ExtValBeanValidationContext.getCurrentInstance().getMessageInterpolator())
>>
>> .constraintValidatorFactory(validatorFactory.getConstraintValidatorFactory())
>>
>> .traversableResolver(validatorFactory.getTraversableResolver())
>>                 .getValidator()
>>                 .validate(validationTarget, groups);
>>
>
> See EXTVAL-86 for the patch.
>
> Include it in the x.x.3 release ?
>
> regards
> Rudy.
>