@Override public void validate() throws InvalidValueException { field.validate(); }
@Override public void validate() throws InvalidValueException { super.validate(); InvalidValueException validationException = null; //validators must be invoked manually for (Field<?> tf : fieldsToValidate.values()) { try { tf.validate(); } catch (InvalidValueException ex) { validationException = ex; } } if (validationException != null) throw validationException; }
@Override public void buttonClick(Button.ClickEvent event) { Map<Field, String> messages = new LinkedHashMap<Field, String>(); for (Object propertyId : form.getItemPropertyIds()) { Field field = form.getField(propertyId); try { field.validate(); } catch (Validator.InvalidValueException e) { messages.put(field, e.getMessage()); } } if (messages.isEmpty()) { form.commit(); callback.onSave(item); } else { StringBuilder sb = new StringBuilder(); for (String msg : messages.values()) { sb.append(msg).append("<br/>"); } validationNotification(getApplication(), getI18NSource(), sb.toString()); } } });
public void validate() throws InvalidValueException { if (property instanceof Validatable) { if (isEmpty()) { if (isRequired()) { throw new Validator.EmptyValueException(getRequiredError()); } else { return; } } if (converter != null) { converter.validate(getValue()); } else { ((Validatable) property).validate(); } } else { wrappedField.validate(); } }
/** * 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; } } } }