Search in sources :

Example 1 with FacesValidatorCDIWrapper

use of org.apache.myfaces.cdi.wrapper.FacesValidatorCDIWrapper in project myfaces by apache.

the class ApplicationImpl method createValidator.

@Override
public final Validator createValidator(final String validatorId) throws FacesException {
    Assert.notEmpty(validatorId, "validatorId");
    Class<? extends Validator> validatorClass = getObjectFromClassMap(validatorId, _validatorClassMap);
    if (validatorClass == null) {
        String message = "Unknown validator id '" + validatorId + "'.";
        log.severe(message);
        throw new FacesException(message);
    }
    try {
        if (!_cdiManagedValidatorMap.containsKey(validatorClass)) {
            FacesValidator annotation = validatorClass.getAnnotation(FacesValidator.class);
            if (annotation != null && annotation.managed()) {
                _cdiManagedValidatorMap.put(validatorClass, true);
            } else {
                _cdiManagedValidatorMap.put(validatorClass, false);
            }
        }
        boolean managed = _cdiManagedValidatorMap.get(validatorClass);
        Validator validator = null;
        if (managed) {
            validator = new FacesValidatorCDIWrapper(validatorClass, validatorId);
            _handleAttachedResourceDependencyAnnotations(getFacesContext(), ((FacesWrapper<Validator>) validator).getWrapped());
        } else {
            validator = createValidatorInstance(validatorClass);
            _handleAttachedResourceDependencyAnnotations(getFacesContext(), validator);
        }
        return validator;
    } catch (Exception e) {
        log.log(Level.SEVERE, "Could not instantiate validator " + validatorClass, e);
        throw new FacesException("Could not instantiate validator: " + validatorClass, e);
    }
}
Also used : FacesValidatorCDIWrapper(org.apache.myfaces.cdi.wrapper.FacesValidatorCDIWrapper) FacesException(jakarta.faces.FacesException) FacesValidator(jakarta.faces.validator.FacesValidator) FacesValidator(jakarta.faces.validator.FacesValidator) Validator(jakarta.faces.validator.Validator) MissingResourceException(java.util.MissingResourceException) NamingException(javax.naming.NamingException) ELException(jakarta.el.ELException) FacesException(jakarta.faces.FacesException)

Aggregations

ELException (jakarta.el.ELException)1 FacesException (jakarta.faces.FacesException)1 FacesValidator (jakarta.faces.validator.FacesValidator)1 Validator (jakarta.faces.validator.Validator)1 MissingResourceException (java.util.MissingResourceException)1 NamingException (javax.naming.NamingException)1 FacesValidatorCDIWrapper (org.apache.myfaces.cdi.wrapper.FacesValidatorCDIWrapper)1