Class DefaultBinderValidationErrorHandler

java.lang.Object
com.vaadin.flow.data.binder.DefaultBinderValidationErrorHandler
All Implemented Interfaces:
BinderValidationErrorHandler, Serializable

public class DefaultBinderValidationErrorHandler extends Object implements BinderValidationErrorHandler
Default implementation of BinderValidationErrorHandler.

This handler applies visual effects for the field if its type allows this:

  • If the field's class implements HasValidation interface then its validity and error message is set based on a ValidationResult
  • If the field's class may have a theme (e.g. implements HasTheme or HasElement) then theme name derived from the ErrorLevel of the ValidationResult instance is applied. E.g., for ErrorLevel.WARNING the element will get the "theme"="warning" attribute and value in HTML.
Author:
Vaadin Ltd
See Also:
  • Constructor Details

    • DefaultBinderValidationErrorHandler

      public DefaultBinderValidationErrorHandler()
  • Method Details

    • handleError

      public void handleError(com.vaadin.flow.component.HasValue<?,?> field, ValidationResult result)
      Handles a validation error emitted when trying to write the value of the given field.
      Specified by:
      handleError in interface BinderValidationErrorHandler
      Parameters:
      field - the field with the invalid value
      result - the validation error result
      See Also:
    • clearError

      public void clearError(com.vaadin.flow.component.HasValue<?,?> field)
      Clears the error condition of the given field, if any.
      Specified by:
      clearError in interface BinderValidationErrorHandler
      Parameters:
      field - the field with an invalid value
      See Also:
    • getErrorThemeName

      protected String getErrorThemeName(ErrorLevel errorLevel)
      Gets the theme name for the ErrorLevel.
      Parameters:
      errorLevel - the error level
      Returns:
      a theme name for the error level
    • getThemes

      protected Optional<com.vaadin.flow.dom.ThemeList> getThemes(com.vaadin.flow.component.HasValue<?,?> field)
      Gets themes for the field.
      Parameters:
      field - a field
      Returns:
      an optional theme list, or an empty optional if the field doesn't have it
    • clearErrorTheme

      protected void clearErrorTheme(com.vaadin.flow.component.HasValue<?,?> field)
      Clears error theme for the field.
      Parameters:
      field - a feild
    • setErrorTheme

      protected void setErrorTheme(com.vaadin.flow.component.HasValue<?,?> field, ValidationResult result)
      Sets error theme for the field based on result.
      Parameters:
      field - a field
      result - a validation result