/** * Clears the error condition of the given field, if any. The default * implementation clears the * {@link AbstractComponent#setComponentError(ErrorMessage) component error} * of the field if it is a Component, otherwise does nothing. * * @param field * the field with an invalid value */ protected void clearError(HasValue<?> field) { if (field instanceof AbstractComponent) { ((AbstractComponent) field).setComponentError(null); } }
@Override public void setComponentError(ErrorMessage componentError) { getRootAbstractComponentOrThrow().setComponentError(componentError); }
/** * Handles a validation error emitted when trying to write the value of the * given field. The default implementation sets the * {@link AbstractComponent#setComponentError(ErrorMessage) component error} * of the field if it is a Component, otherwise does nothing. * * @param field * the field with the invalid value * @param result * the validation error result * * @since 8.2 */ protected void handleError(HasValue<?> field, ValidationResult result) { result.getErrorLevel().ifPresent(level -> { if (field instanceof AbstractComponent) { ((AbstractComponent) field).setComponentError(new UserError( result.getErrorMessage(), ContentMode.TEXT, level)); } }); }
public static void doDefault(ErrorEvent event) { Throwable t = event.getThrowable(); if (t instanceof SocketException) { // Most likely client browser closed socket getLogger().info("SocketException in CommunicationManager." + " Most likely client (browser) closed socket."); return; } t = findRelevantThrowable(t); // Finds the original source of the error/exception AbstractComponent component = findAbstractComponent(event); if (component != null) { // Shows the error in AbstractComponent ErrorMessage errorMessage = AbstractErrorMessage .getErrorMessageForException(t); component.setComponentError(errorMessage); } // also print the error on console getLogger().log(Level.SEVERE, "", t); }
/** * Sets the component's error message. * * @param componentError * the new <code>ErrorMessage</code> of the component. * @return this (for method chaining) * @see AbstractComponent#setComponentError(com.vaadin.server.ErrorMessage) */ public default S withComponentError(ErrorMessage componentError) { ((AbstractComponent) this).setComponentError(componentError); return (S) this; }
com.vaadin.server.AbstractErrorMessage.ContentMode.HTML, ErrorLevel.ERROR); setComponentError(error);
private void clearMValidationErrors() { for (AbstractComponent value : mValidationErrors.values()) { if (value != null) { value.setComponentError(null); } } mValidationErrors.clear(); for (AbstractComponent ac : validatorToErrorTarget.values()) { ac.setComponentError(null); } }
protected void setValidationError(String errorMessage) { if (getComposition() instanceof AbstractComponent) { AbstractComponent composition = (AbstractComponent) getComposition(); if (errorMessage == null) { composition.setComponentError(null); } else { composition.setComponentError(new UserError(errorMessage)); } } } }
private void enableField(Field<?> field, boolean enabled) { field.setEnabled(enabled); // we revert changes, when we disable the fields if (!enabled) { field.discard(); // hide validation errors when disabled if (field instanceof AbstractComponent) { ((AbstractComponent) field).setComponentError(null); } } } @Override
private static void setComponentError(ValueComponent<?> valueComponent, String error) { final Component c = valueComponent.getComponent(); if (c != null && c instanceof AbstractComponent) { ((AbstractComponent) c).setComponentError((error == null) ? null : new UserError(error)); } }
private void enableField(Field<?> field, boolean enabled) { field.setEnabled(enabled); // we revert changes, when we disable the fields if (!enabled) { field.discard(); // hide validation errors when disabled if (field instanceof AbstractComponent) { ((AbstractComponent) field).setComponentError(null); } } } @Override
private static void setComponentError(ValueComponent<?> valueComponent, String error) { final Component c = valueComponent.getComponent(); if (c != null && c instanceof AbstractComponent) { ((AbstractComponent) c).setComponentError((error == null) ? null : new UserError(error)); } }
@Override public void setErrorMessage(String msg) { getLabel().setComponentError(msg == null ? null : new UserError(msg)); }
if (errortarget != null) { errortarget.setComponentError(new UserError( constraintViolation.getMessage())); iterator.remove();
public void valueChange(ValueChangeEvent event) { logger.debug("Changed value "); Property<?> p = abstractField.getPropertyDataSource(); if (p instanceof MaduraPropertyWrapper) { MaduraPropertyWrapper property = (MaduraPropertyWrapper) p; if (property.getErrorText() != null) { field.setComponentError(new UserError(property .getErrorText())); } else { field.setComponentError(null); } } updateOtherFields(abstractField); } });
getErrorMessageForException(e); mValidationErrors.put(em, field); field.setComponentError(em); getClass()); if (target != null) { target.setComponentError(em); } else {
/** * 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; } } } }
/** * 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; } } } }
getErrorMessageForException(e); mValidationErrors.put(em, field); field.setComponentError(em); getClass()); if (target != null) { target.setComponentError(em); } else {
((AbstractComponent) owner).setComponentError((ErrorMessage) t); } else { ((AbstractComponent) owner) .setComponentError(new SystemError(t));