getModelType(), getLocale()); } catch (ConversionException e) { throw new InvalidValueException( getConversionError(getConverter().getModelType(), e)); throw new Validator.InvalidValueException(null, exceptionArray);
errors.add(cv.getMessage());
/** * Check if the error message should be hidden. * * An empty (null or "") message is invisible unless it contains nested * exceptions that are visible. * * @return true if the error message should be hidden, false otherwise */ public boolean isInvisible() { String msg = getMessage(); if (msg != null && !msg.isEmpty()) { return false; } if (causes != null) { for (InvalidValueException e : causes) { if (!e.isInvisible()) { return false; } } } return true; }
int intValue = Integer.parseInt((String) value); if (intValue <= 0) { throw new Validator.InvalidValueException("Weight must be > 0"); throw new Validator.InvalidValueException("Weight must be a number");
throw new Validator.InvalidValueException("Threshold must be a positive number"); throw new Validator.InvalidValueException("Base must be greater than 1.0");
if (value != null) { if (((Integer) value).intValue() <= 0) { throw new Validator.InvalidValueException("must be > 0"); if (value != null) { if (((Long) value).intValue() <= 0) { throw new Validator.InvalidValueException("must be > 0");
throw new Validator.InvalidValueException(em); } else { throw first;
validate(); } catch (Validator.InvalidValueException e) { if (!e.isInvisible()) { validationError = e;
.getHeaderCaption(); String message = invalidFields.get(firstErrorField) .getLocalizedMessage();
/** * Validates the given field and sets the component error accordingly. * Please note, that the provided field must implement {@link Field} and must be a sub class of {@link AbstractComponent}. * * @param field The field to validate (must be a sub class of {@link AbstractComponent}). * @param swallowValidationExceptions Indicates if an InvalidValueException is swallowed and not propagated. * If false the first occurring InvalidValueException is thrown. * @throws Validator.InvalidValueException If the field is not valid (see {@link Validator#validate(Object)}. */ public static void validateField(Field<?> field, boolean swallowValidationExceptions) throws Validator.InvalidValueException { if (field instanceof AbstractComponent && field.isEnabled()) { try { field.validate(); ((AbstractComponent) field).setComponentError(null); } catch (Validator.InvalidValueException ex) { // Some fields unify exceptions, we have to consider this if (ex.getMessage() == null) { ex = ex.getCauses()[0]; } // set error message ((AbstractComponent) field).setComponentError(new UserError(ex.getMessage())); if (!swallowValidationExceptions) { throw ex; } } } }
protected Validator.InvalidValueException getValidationError() { if (isEagerValidation() && lastKnownTextChangeValue != null) { return eagerValidationError; } /* * Check validation errors only if automatic validation is enabled. * Empty, required fields will generate a validation error containing * the requiredError string. For these fields the exclamation mark will * be hidden but the error must still be sent to the client. */ Validator.InvalidValueException validationError = null; if (isValidationVisible()) { try { validate(); } catch (Validator.InvalidValueException e) { if (!e.isInvisible()) { validationError = e; } } } return validationError; }
protected Validator.InvalidValueException getValidationError() { if (isEagerValidation() && lastKnownTextChangeValue != null) { return eagerValidationError; } /* * Check validation errors only if automatic validation is enabled. * Empty, required fields will generate a validation error containing * the requiredError string. For these fields the exclamation mark will * be hidden but the error must still be sent to the client. */ Validator.InvalidValueException validationError = null; if (isValidationVisible()) { try { validate(); } catch (Validator.InvalidValueException e) { if (!e.isInvisible()) { validationError = e; } } } return validationError; }
@Override public void validate(final Object value) throws InvalidValueException { Set<?> violations = getJavaxBeanValidator().validateValue(beanClass, propertyName, value); if (!violations.isEmpty()) { InvalidValueException[] causes = new InvalidValueException[violations .size()]; int i = 0; for (Object v : violations) { final ConstraintViolation<?> violation = (ConstraintViolation<?>) v; String msg = getJavaxBeanValidatorFactory() .getMessageInterpolator() .interpolate(violation.getMessageTemplate(), new SimpleContext(value, violation.getConstraintDescriptor()), locale); causes[i] = new InvalidValueException(msg); ++i; } throw new InvalidValueException(null, causes); } }
/** * Validates the data given in value. * * @param value * the value to validate. * @throws Validator.InvalidValueException * if the value was invalid. */ @Override public void validate(Object value) throws Validator.InvalidValueException { if ((onlyNullAllowed && value != null) || (!onlyNullAllowed && value == null)) { throw new Validator.InvalidValueException(errorMessage); } }
@Override public void validate(Object value) throws InvalidValueException { // isValidType ensures that value can safely be cast to TYPE if (!isValidType(value) || !isValidValue((T) value)) { String message = getErrorMessage().replace("{0}", String.valueOf(value)); throw new InvalidValueException(message); } }
/** * Returns the message of the error in HTML. * * Note that this API may change in future versions. */ public String getHtmlMessage() { return VaadinServlet.safeEscapeForHtml(getLocalizedMessage()); }
@Override public ErrorMessage getErrorMessage() { UserError error = new UserError(getHtmlMessage(), ContentMode.HTML, ErrorLevel.ERROR); for (Validator.InvalidValueException nestedException : getCauses()) { error.addCause(AbstractErrorMessage .getErrorMessageForException(nestedException)); } return error; }