Search in sources :

Example 1 with CompositeValidationException

use of com.haulmont.cuba.gui.components.CompositeValidationException in project cuba by cuba-platform.

the class BeanValidator method validate.

@Override
public void validate(Object value) throws ValidationException {
    BeanValidation beanValidation = AppBeans.get(BeanValidation.NAME);
    Validator validator = beanValidation.getValidator();
    Class[] groups = this.validationGroups;
    if (groups == null || groups.length == 0) {
        groups = new Class[] { Default.class, UiComponentChecks.class };
    }
    @SuppressWarnings("unchecked") Set<ConstraintViolation> violations = validator.validateValue(beanClass, beanProperty, value, groups);
    if (!violations.isEmpty()) {
        List<CompositeValidationException.ViolationCause> causes = new ArrayList<>();
        for (ConstraintViolation violation : violations) {
            causes.add(new BeanValidationViolationCause(violation));
        }
        String validationMessage = this.validationErrorMessage;
        if (validationMessage == null) {
            validationMessage = getDefaultErrorMessage();
        }
        throw new CompositeValidationException(validationMessage, causes);
    }
}
Also used : BeanValidation(com.haulmont.cuba.core.global.BeanValidation) ArrayList(java.util.ArrayList) ConstraintViolation(javax.validation.ConstraintViolation) MetaClass(com.haulmont.chile.core.model.MetaClass) CompositeValidationException(com.haulmont.cuba.gui.components.CompositeValidationException) Validator(javax.validation.Validator)

Aggregations

MetaClass (com.haulmont.chile.core.model.MetaClass)1 BeanValidation (com.haulmont.cuba.core.global.BeanValidation)1 CompositeValidationException (com.haulmont.cuba.gui.components.CompositeValidationException)1 ArrayList (java.util.ArrayList)1 ConstraintViolation (javax.validation.ConstraintViolation)1 Validator (javax.validation.Validator)1