Search in sources :

Example 1 with ValidatorContext

use of jakarta.validation.ValidatorContext in project glassfish-hk2 by eclipse-ee4j.

the class ValidatorUtilities method initializeValidator.

private static Validator initializeValidator() {
    ClassLoader cl = Thread.currentThread().getContextClassLoader();
    try {
        Thread.currentThread().setContextClassLoader(HibernateValidator.class.getClassLoader());
        ValidatorFactory validatorFactory = Validation.buildDefaultValidatorFactory();
        ValidatorContext validatorContext = validatorFactory.usingContext();
        validatorContext.messageInterpolator(new MessageInterpolatorImpl());
        return validatorContext.traversableResolver(TRAVERSABLE_RESOLVER).getValidator();
    } finally {
        Thread.currentThread().setContextClassLoader(cl);
    }
}
Also used : HibernateValidator(org.hibernate.validator.HibernateValidator) ValidatorFactory(jakarta.validation.ValidatorFactory) ValidatorContext(jakarta.validation.ValidatorContext) MessageInterpolatorImpl(org.glassfish.hk2.utilities.general.internal.MessageInterpolatorImpl)

Example 2 with ValidatorContext

use of jakarta.validation.ValidatorContext in project mojarra by eclipse-ee4j.

the class BeanValidation method getBeanValidator.

public static Validator getBeanValidator(FacesContext context) {
    ValidatorFactory validatorFactory = getValidatorFactory(context);
    ValidatorContext validatorContext = validatorFactory.usingContext();
    MessageInterpolator facesMessageInterpolator = new FacesAwareMessageInterpolator(context, validatorFactory.getMessageInterpolator());
    validatorContext.messageInterpolator(facesMessageInterpolator);
    return validatorContext.getValidator();
}
Also used : Validation.buildDefaultValidatorFactory(jakarta.validation.Validation.buildDefaultValidatorFactory) ValidatorFactory(jakarta.validation.ValidatorFactory) ValidatorContext(jakarta.validation.ValidatorContext) MessageInterpolator(jakarta.validation.MessageInterpolator)

Example 3 with ValidatorContext

use of jakarta.validation.ValidatorContext in project today-infrastructure by TAKETODAY.

the class CustomValidatorBean method afterPropertiesSet.

@Override
public void afterPropertiesSet() {
    if (this.validatorFactory == null) {
        this.validatorFactory = Validation.buildDefaultValidatorFactory();
    }
    ValidatorContext validatorContext = this.validatorFactory.usingContext();
    MessageInterpolator targetInterpolator = this.messageInterpolator;
    if (targetInterpolator == null) {
        targetInterpolator = this.validatorFactory.getMessageInterpolator();
    }
    validatorContext.messageInterpolator(new LocaleContextMessageInterpolator(targetInterpolator));
    if (this.traversableResolver != null) {
        validatorContext.traversableResolver(this.traversableResolver);
    }
    setTargetValidator(validatorContext.getValidator());
}
Also used : ValidatorContext(jakarta.validation.ValidatorContext) MessageInterpolator(jakarta.validation.MessageInterpolator)

Example 4 with ValidatorContext

use of jakarta.validation.ValidatorContext in project spring-framework by spring-projects.

the class CustomValidatorBean method afterPropertiesSet.

@Override
public void afterPropertiesSet() {
    if (this.validatorFactory == null) {
        this.validatorFactory = Validation.buildDefaultValidatorFactory();
    }
    ValidatorContext validatorContext = this.validatorFactory.usingContext();
    MessageInterpolator targetInterpolator = this.messageInterpolator;
    if (targetInterpolator == null) {
        targetInterpolator = this.validatorFactory.getMessageInterpolator();
    }
    validatorContext.messageInterpolator(new LocaleContextMessageInterpolator(targetInterpolator));
    if (this.traversableResolver != null) {
        validatorContext.traversableResolver(this.traversableResolver);
    }
    setTargetValidator(validatorContext.getValidator());
}
Also used : ValidatorContext(jakarta.validation.ValidatorContext) MessageInterpolator(jakarta.validation.MessageInterpolator)

Example 5 with ValidatorContext

use of jakarta.validation.ValidatorContext in project mojarra by eclipse-ee4j.

the class BeanValidator method getBeanValidator.

// ----------------------------------------------------- Private helper methods for bean validation
// MOJARRA IMPLEMENTATION NOTE: identical code exists in Mojarra's com.sun.faces.util.BeanValidation
private static jakarta.validation.Validator getBeanValidator(FacesContext context) {
    ValidatorFactory validatorFactory = getValidatorFactory(context);
    ValidatorContext validatorContext = validatorFactory.usingContext();
    MessageInterpolator facesMessageInterpolator = new FacesAwareMessageInterpolator(context, validatorFactory.getMessageInterpolator());
    validatorContext.messageInterpolator(facesMessageInterpolator);
    return validatorContext.getValidator();
}
Also used : ValidatorFactory(jakarta.validation.ValidatorFactory) ValidatorContext(jakarta.validation.ValidatorContext) MessageInterpolator(jakarta.validation.MessageInterpolator)

Aggregations

ValidatorContext (jakarta.validation.ValidatorContext)6 MessageInterpolator (jakarta.validation.MessageInterpolator)5 ValidatorFactory (jakarta.validation.ValidatorFactory)3 Validation.buildDefaultValidatorFactory (jakarta.validation.Validation.buildDefaultValidatorFactory)1 MessageInterpolatorImpl (org.glassfish.hk2.utilities.general.internal.MessageInterpolatorImpl)1 HibernateValidator (org.hibernate.validator.HibernateValidator)1