Example usage for com.vaadin.server UserError UserError

List of usage examples for com.vaadin.server UserError UserError

Introduction

In this page you can find the example usage for com.vaadin.server UserError UserError.

Prototype

public UserError(String textErrorMessage) 

Source Link

Document

Creates a textual error message of level ERROR.

Usage

From source file:org.vaadin.viritin.MBeanFieldGroup.java

License:Apache License

protected boolean jsr303ValidateBean(T bean) {
    try {/* w  ww.  j  av a2 s.  c o m*/
        if (javaxBeanValidator == null) {
            javaxBeanValidator = getJavaxBeanValidatorFactory().getValidator();
        }
    } catch (Throwable t) {
        // This may happen without JSR303 validation framework
        Logger.getLogger(getClass().getName()).fine("JSR303 validation failed");
        return true;
    }

    Set<ConstraintViolation<T>> constraintViolations = new HashSet(
            javaxBeanValidator.validate(bean, getValidationGroups()));
    if (constraintViolations.isEmpty()) {
        return true;
    }
    Iterator<ConstraintViolation<T>> iterator = constraintViolations.iterator();
    while (iterator.hasNext()) {
        ConstraintViolation<T> constraintViolation = iterator.next();
        Class<? extends Annotation> annotationType = constraintViolation.getConstraintDescriptor()
                .getAnnotation().annotationType();
        AbstractComponent errortarget = validatorToErrorTarget.get(annotationType);
        if (errortarget != null) {
            // user has declared a target component for this constraint
            errortarget.setComponentError(new UserError(constraintViolation.getMessage()));
            iterator.remove();
        }
        // else leave as "bean level error"
    }
    this.jsr303beanLevelViolations = constraintViolations;
    return false;
}

From source file:org.vaadin.viritin.v7.MBeanFieldGroup.java

License:Apache License

protected boolean jsr303ValidateBean(T bean) {
    try {/*  www .j ava2 s  .c o m*/
        if (javaxBeanValidator == null) {
            javaxBeanValidator = getJavaxBeanValidatorFactory().getValidator();
        }
    } catch (Throwable t) {
        // This may happen without JSR303 validation framework
        Logger.getLogger(getClass().getName()).fine("JSR303 validation failed");
        return true;
    }

    boolean containsAtLeastOneBoundComponentWithError = false;
    Set<ConstraintViolation<T>> constraintViolations = new HashSet<>(
            javaxBeanValidator.validate(bean, getValidationGroups()));
    if (constraintViolations.isEmpty()) {
        return true;
    }
    Iterator<ConstraintViolation<T>> iterator = constraintViolations.iterator();
    while (iterator.hasNext()) {
        ConstraintViolation<T> constraintViolation = iterator.next();
        Class<? extends Annotation> annotationType = constraintViolation.getConstraintDescriptor()
                .getAnnotation().annotationType();
        AbstractComponent errortarget = validatorToErrorTarget.get(annotationType);
        if (errortarget != null) {
            // user has declared a target component for this constraint
            errortarget.setComponentError(new UserError(constraintViolation.getMessage()));
            iterator.remove();
            containsAtLeastOneBoundComponentWithError = true;
        }
        // else leave as "bean level error"
    }
    this.jsr303beanLevelViolations = constraintViolations;
    if (!containsAtLeastOneBoundComponentWithError && isValidateOnlyBoundFields()) {
        return true;
    }
    return false;
}