Package com.vaadin.flow.data.binder
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 ofBinderValidationErrorHandler.This handler applies visual effects for the field if its type allows this:
- If the field's class implements
HasValidationinterface then its validity and error message is set based on aValidationResult - If the field's class may have a theme (e.g. implements
HasThemeorHasElement) then theme name derived from theErrorLevelof theValidationResultinstance is applied. E.g., forErrorLevel.WARNINGthe element will get the "theme"="warning" attribute and value in HTML.
- Since:
- Author:
- Vaadin Ltd
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description DefaultBinderValidationErrorHandler()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclearError(HasValue<?,?> field)Clears the error condition of the given field, if any.protected voidclearErrorTheme(HasValue<?,?> field)Clears error theme for thefield.protected StringgetErrorThemeName(ErrorLevel errorLevel)Gets the theme name for theErrorLevel.protected Optional<ThemeList>getThemes(HasValue<?,?> field)Gets themes for thefield.voidhandleError(HasValue<?,?> field, ValidationResult result)Handles a validation error emitted when trying to write the value of the given field.protected voidsetErrorTheme(HasValue<?,?> field, ValidationResult result)Sets error theme for thefieldbased onresult.
-
-
-
Method Detail
-
handleError
public void handleError(HasValue<?,?> field, ValidationResult result)
Handles a validation error emitted when trying to write the value of the given field.- Specified by:
handleErrorin interfaceBinderValidationErrorHandler- Parameters:
field- the field with the invalid valueresult- the validation error result- See Also:
BinderValidationErrorHandler.clearError(HasValue)
-
clearError
public void clearError(HasValue<?,?> field)
Clears the error condition of the given field, if any.- Specified by:
clearErrorin interfaceBinderValidationErrorHandler- Parameters:
field- the field with an invalid value- See Also:
BinderValidationErrorHandler.handleError(HasValue, ValidationResult)
-
getErrorThemeName
protected String getErrorThemeName(ErrorLevel errorLevel)
Gets the theme name for theErrorLevel.- Parameters:
errorLevel- the error level- Returns:
- a theme name for the error level
-
getThemes
protected Optional<ThemeList> getThemes(HasValue<?,?> field)
Gets themes for thefield.- Parameters:
field- a field- Returns:
- an optional theme list, or an empty optional if the
fielddoesn't have it
-
clearErrorTheme
protected void clearErrorTheme(HasValue<?,?> field)
Clears error theme for thefield.- Parameters:
field- a feild
-
setErrorTheme
protected void setErrorTheme(HasValue<?,?> field, ValidationResult result)
Sets error theme for thefieldbased onresult.- Parameters:
field- a fieldresult- a validation result
-
-