protected <T> ClassValidator<T> getValidator(Class<T> modelClass) { return Validators.instance().getValidator(modelClass); }
/** * Get the cached ClassValidator instance. * * @param modelClass the class to be validated */ public <T> ClassValidator<T> getValidator(Class<T> modelClass) { return createValidator(modelClass); }
/** * Validate the value against model-based constraints return true if the * value is valid */ protected boolean validateValue(String valueExpression, Object value) { ValueExpression ve = application.getExpressionFactory().createValueExpression(facesContext.getELContext(), valueExpression, Object.class); Set<ConstraintViolation<Object>> ivs = Validators.instance().validate(ve, facesContext.getELContext(), value); if (ivs.size() > 0) { validationFailed = true; String message = ivs.iterator().next().getMessage(); facesContext.addMessage(null, FacesMessages.createFacesMessage(FacesMessage.SEVERITY_ERROR, message)); return false; } else { return true; } }
@Override public void setValue(ELContext context, Object base, Object property, Object value) throws NullPointerException, PropertyNotFoundException, PropertyNotWritableException, ELException { if (base != null && property != null) { context.setPropertyResolved(true); invalidValues = getValidator(base).getPotentialInvalidValues(property.toString(), value); } }
public void validate(FacesContext facesContext, UIComponent component, Object value) throws ValidatorException { ValueExpression valueExpression = component.getValueExpression("value"); if (valueExpression != null) { //TODO: note that this code is duplicated to Param.getValueFromRequest()!! Set<ConstraintViolation<Object>> invalidValues; try { invalidValues = Validators.instance().validate( valueExpression, facesContext.getELContext(), value ); } catch (ELException ele) { Throwable cause = ele.getCause(); if (cause==null) cause = ele; throw new ValidatorException(createMessage(cause), cause); } if ( invalidValues!=null && invalidValues.size()>0 ) { throw new ValidatorException(createMessage(invalidValues, resolveLabel(facesContext, component))); } } }
/** * Get the cached ClassValidator instance. If the argument is an instance of * a session bean Seam component instance, the returned validator will be * aware of constraints defined on the bean class. Therefore this method is * preferred to getValidator(Class) if the argument might be a session bean. * * @param model the object to be validated */ @SuppressWarnings("unchecked") public <T> ClassValidator<T> getValidator(T model) { Class<?> modelClass = model instanceof Instance ? ((Instance) model).getComponent().getBeanClass() : model.getClass(); return getValidator((Class<T>) modelClass); }
protected <T> ClassValidator<T> getValidator(T model) { return Validators.instance().getValidator(model); }