private Validator getDefaultValidator ( final FacesContext context ) throws FacesException { if ( ! beanValidationPresent ) { return null ; } ValidatorFactory validatorFactory ; Object cachedObject = context . getExternalContext ( ) . getApplicationMap ( ) . get ( BeanValidator . VALIDATOR_FACTORY_KEY ) ; if ( cachedObject instanceof ValidatorFactory ) { validatorFactory = ( ValidatorFactory ) cachedObject ; } else { try { validatorFactory = Validation . buildDefaultValidatorFactory ( ) ; } catch ( ValidationException e ) { throw new FacesException ( "Could not build a default Bean Validator factory" , e ) ; } context . getExternalContext ( ) . getApplicationMap ( ) . put ( BeanValidator . VALIDATOR_FACTORY_KEY , validatorFactory ) ; } return validatorFactory . getValidator ( ) ; }
Get the default Bean Validation Validator to read the contraints for a property .