protected void validate(Validatable validatable, ValidationErrors errors) { try { validatable.validate(); } catch (ValidationException e) { Logger log = LoggerFactory.getLogger(Screen.class); if (log.isTraceEnabled()) { log.trace("Validation failed", e); } else if (log.isDebugEnabled()) { log.debug("Validation failed: " + e); } ComponentsHelper.fillErrorMessages(validatable, e, errors); } }
@Override public boolean validate(List<Validatable> fields) { ValidationErrors errors = new ValidationErrors(); for (Validatable field : fields) { try { field.validate(); } catch (ValidationException e) { if (log.isTraceEnabled()) log.trace("Validation failed", e); else if (log.isDebugEnabled()) log.debug("Validation failed: " + e); ComponentsHelper.fillErrorMessages(field, e, errors); } } return handleValidationErrors(errors); }
@Override public boolean validate(List<Validatable> fields) { ValidationErrors errors = new ValidationErrors(); for (Validatable field : fields) { try { field.validate(); } catch (ValidationException e) { if (log.isTraceEnabled()) log.trace("Validation failed", e); else if (log.isDebugEnabled()) log.debug("Validation failed: " + e); ComponentsHelper.fillErrorMessages(field, e, errors); } } return handleValidationErrors(errors); }
@Override public boolean validateAll() { ValidationErrors errors = new ValidationErrors(); ComponentsHelper.traverseValidatable(this, v -> { try { v.validate(); } catch (ValidationException e) { if (log.isTraceEnabled()) { log.trace("Validation failed", e); } else if (log.isDebugEnabled()) { log.debug("Validation failed: " + e); } ComponentsHelper.fillErrorMessages(v, e, errors); } }); return handleValidationErrors(errors); }
@Override public boolean validateAll() { ValidationErrors errors = new ValidationErrors(); ComponentsHelper.traverseValidatable(this, v -> { try { v.validate(); } catch (ValidationException e) { if (log.isTraceEnabled()) { log.trace("Validation failed", e); } else if (log.isDebugEnabled()) { log.debug("Validation failed: " + e); } ComponentsHelper.fillErrorMessages(v, e, errors); } }); return handleValidationErrors(errors); }
/** * Place component with error message to validation errors container. * * @param component validatable component * @param e exception * @param errors errors container */ public static void fillErrorMessages(Validatable component, ValidationException e, ValidationErrors errors) { if (e instanceof ValidationException.HasRelatedComponent) { errors.add(((ValidationException.HasRelatedComponent) e).getComponent(), e.getMessage()); } else if (e instanceof CompositeValidationException) { for (CompositeValidationException.ViolationCause cause : ((CompositeValidationException) e).getCauses()) { errors.add((Component) component, cause.getMessage()); } } else if (e instanceof FieldGroup.FieldsValidationException) { FieldGroup.FieldsValidationException fve = (FieldGroup.FieldsValidationException) e; Map<Validatable, ValidationException> fields = fve.getProblemFields(); for (Map.Entry<Validatable, ValidationException> problem : fields.entrySet()) { ValidationException exception = problem.getValue(); fillErrorMessages(problem.getKey(), exception, errors); } } else { errors.add((Component) component, e.getMessage()); } }