List of usage examples for com.vaadin.ui AbstractComponent setComponentError
public void setComponentError(ErrorMessage componentError)
From source file:org.vaadin.viritin.MBeanFieldGroup.java
License:Apache License
@Override public boolean isValid() { // clear all MValidation errors clearMValidationErrors();//from w w w .ja v a2s . com jsr303beanLevelViolations = null; beanLevelViolations = null; // first check standard property level validators final boolean propertiesValid = super.isValid(); // then crossfield(/bean level) validators, execute them all although // with per field validation Vaadin checks only until the first failed one if (propertiesValid) { boolean ok = true; for (MValidator<T> v : mValidators.keySet()) { try { v.validate(getItemDataSource().getBean()); } catch (Validator.InvalidValueException e) { Collection<AbstractComponent> properties = mValidators.get(v); if (!properties.isEmpty()) { for (AbstractComponent field : properties) { final ErrorMessage em = AbstractErrorMessage.getErrorMessageForException(e); mValidationErrors.put(em, field); field.setComponentError(em); } } else { final ErrorMessage em = AbstractErrorMessage.getErrorMessageForException(e); AbstractComponent target = validatorToErrorTarget.get(v.getClass()); if (target != null) { target.setComponentError(em); } else { // no specific "target component" for validation error // leave as bean level error if (beanLevelViolations == null) { beanLevelViolations = new HashSet<Validator.InvalidValueException>(); } beanLevelViolations.add(e); mValidationErrors.put(em, null); } } ok = false; } } return jsr303ValidateBean(getItemDataSource().getBean()) && ok; } return false; }
From source file:org.vaadin.viritin.v7.MBeanFieldGroup.java
License:Apache License
protected boolean jsr303ValidateBean(T bean) { try {/*from w ww .java 2 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; }
From source file:org.vaadin.viritin.v7.MBeanFieldGroup.java
License:Apache License
private boolean isValidAllProperties() { // clear all MValidation errors clearMValidationErrors();/*from www. j av a 2 s.c o m*/ jsr303beanLevelViolations = null; beanLevelViolations = null; // first check standard property level validators, but unlike in Vaadin // core, check them all, don't stop for first error boolean propertiesValid = true; try { for (Field<?> field : getFields()) { field.validate(); } } catch (Validator.InvalidValueException e) { propertiesValid = false; } // then crossfield(/bean level) validators, execute them all although // with per field validation Vaadin checks only until the first failed one boolean ok = true; for (MValidator<T> v : mValidators.keySet()) { try { v.validate(getItemDataSource().getBean()); } catch (Validator.InvalidValueException e) { Collection<AbstractComponent> properties = mValidators.get(v); if (!properties.isEmpty()) { for (AbstractComponent field : properties) { final ErrorMessage em = AbstractErrorMessage.getErrorMessageForException(e); mValidationErrors.put(em, field); field.setComponentError(em); } } else { final ErrorMessage em = AbstractErrorMessage.getErrorMessageForException(e); AbstractComponent target = validatorToErrorTarget.get(v.getClass()); if (target != null) { target.setComponentError(em); } else { // no specific "target component" for validation error // leave as bean level error if (beanLevelViolations == null) { beanLevelViolations = new HashSet<>(); } beanLevelViolations.add(e); mValidationErrors.put(em, null); } } ok = false; } } return jsr303ValidateBean(getItemDataSource().getBean()) && ok && propertiesValid; }
From source file:org.vaadin.viritin.v7.MBeanFieldGroup.java
License:Apache License
private boolean isValidLegacy() { // clear all MValidation errors clearMValidationErrors();/*from w ww . j a va 2 s . co m*/ jsr303beanLevelViolations = null; beanLevelViolations = null; // first check standard property level validators final boolean propertiesValid = super.isValid(); // then crossfield(/bean level) validators, execute them all although // with per field validation Vaadin checks only until the first failed one if (propertiesValid) { boolean ok = true; for (MValidator<T> v : mValidators.keySet()) { try { v.validate(getItemDataSource().getBean()); } catch (Validator.InvalidValueException e) { Collection<AbstractComponent> properties = mValidators.get(v); if (!properties.isEmpty()) { for (AbstractComponent field : properties) { final ErrorMessage em = AbstractErrorMessage.getErrorMessageForException(e); mValidationErrors.put(em, field); field.setComponentError(em); } } else { final ErrorMessage em = AbstractErrorMessage.getErrorMessageForException(e); AbstractComponent target = validatorToErrorTarget.get(v.getClass()); if (target != null) { target.setComponentError(em); } else { // no specific "target component" for validation error // leave as bean level error if (beanLevelViolations == null) { beanLevelViolations = new HashSet<>(); } beanLevelViolations.add(e); mValidationErrors.put(em, null); } } ok = false; } } return jsr303ValidateBean(getItemDataSource().getBean()) && ok; } return false; }