com.vaadin.flow.component.textfield.
Class EmailField
- java.lang.Object
-
- com.vaadin.flow.component.Component
-
- com.vaadin.flow.component.AbstractField<C,T>
-
- com.vaadin.flow.component.AbstractSinglePropertyField<R,T>
-
- com.vaadin.flow.component.textfield.GeneratedVaadinTextField<R,T>
-
- com.vaadin.flow.component.textfield.GeneratedVaadinEmailField<EmailField,String>
-
- com.vaadin.flow.component.textfield.EmailField
-
All Implemented Interfaces:
AttachNotifier, BlurNotifier<EmailField>, CompositionNotifier, DetachNotifier, Focusable<EmailField>, FocusNotifier<EmailField>, HasElement, HasEnabled, HasHelper, HasLabel, HasSize, HasStyle, HasTheme, HasValidation, HasValue<AbstractField.ComponentValueChangeEvent<EmailField,String>,String>, HasValueAndElement<AbstractField.ComponentValueChangeEvent<EmailField,String>,String>, InputNotifier, KeyNotifier, HasClientValidation, HasAutocapitalize, HasAutocomplete, HasAutocorrect, HasPrefixAndSuffix, HasValidator<String>, HasValueChangeMode, Serializable
public class EmailField extends GeneratedVaadinEmailField<EmailField,String> implements HasSize, HasValidation, HasValueChangeMode, HasPrefixAndSuffix, InputNotifier, KeyNotifier, CompositionNotifier, HasAutocomplete, HasAutocapitalize, HasAutocorrect, HasHelper, HasLabel, HasValidator<String>, HasClientValidation
Server-side component for the
vaadin-email-field
element.Author:
Vaadin Ltd.
See Also:
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class com.vaadin.flow.component.textfield.GeneratedVaadinTextField
GeneratedVaadinTextField.ChangeEvent<R extends GeneratedVaadinTextField<R,?>>, GeneratedVaadinTextField.InvalidChangeEvent<R extends GeneratedVaadinTextField<R,?>>
-
Nested classes/interfaces inherited from class com.vaadin.flow.component.AbstractField
AbstractField.ComponentValueChangeEvent<C extends Component,V>
-
Nested classes/interfaces inherited from interface com.vaadin.flow.component.shared.HasClientValidation
HasClientValidation.ClientValidatedEvent
-
Nested classes/interfaces inherited from interface com.vaadin.flow.component.BlurNotifier
BlurNotifier.BlurEvent<C extends Component>
-
Nested classes/interfaces inherited from interface com.vaadin.flow.component.FocusNotifier
FocusNotifier.FocusEvent<C extends Component>
-
Nested classes/interfaces inherited from interface com.vaadin.flow.component.HasValue
HasValue.ValueChangeEvent<V>, HasValue.ValueChangeListener<E extends HasValue.ValueChangeEvent<?>>
-
-
Field Summary
-
Fields inherited from interface com.vaadin.flow.data.value.HasValueChangeMode
DEFAULT_CHANGE_TIMEOUT
-
Fields inherited from interface com.vaadin.flow.component.textfield.HasAutocomplete
AUTOCOMPLETE_ATTRIBUTE
-
Fields inherited from interface com.vaadin.flow.component.textfield.HasAutocapitalize
AUTOCAPITALIZE_ATTRIBUTE
-
Fields inherited from interface com.vaadin.flow.component.textfield.HasAutocorrect
AUTOCORRECT_ATTRIBUTE
-
-
Constructor Summary
Constructors Constructor and Description EmailField()
Constructs an empty
EmailField
.EmailField(HasValue.ValueChangeListener<? super AbstractField.ComponentValueChangeEvent<EmailField,String>> listener)
Constructs an empty
EmailField
with a value change listener.EmailField(String label)
Constructs an empty
EmailField
with the given label.EmailField(String label, HasValue.ValueChangeListener<? super AbstractField.ComponentValueChangeEvent<EmailField,String>> listener)
Constructs an empty
EmailField
with a value change listener and a label.EmailField(String label, String placeholder)
Constructs an empty
EmailField
with the given label and placeholder text.EmailField(String label, String initialValue, HasValue.ValueChangeListener<? super AbstractField.ComponentValueChangeEvent<EmailField,String>> listener)
Constructs a
EmailField
with a value change listener, a label and an initial value.
-
Method Summary
All Methods Modifier and Type Method and Description Registration
addValidationStatusChangeListener(ValidationStatusChangeListener<String> listener)
Enables the implementing components to notify changes in their validation status to the observers.
Validator<String>
getDefaultValidator()
Returns a validator that checks the state of the Value.
String
getEmptyValue()
Returns the value that represents an empty value.
String
getErrorMessage()
Gets current error message from the component.
String
getLabel()
String used for the label element.
int
getMaxLength()
Maximum number of characters (in Unicode code points) that the user can enter.
int
getMinLength()
Minimum number of characters (in Unicode code points) that the user can enter.
String
getPattern()
A regular expression that the value is checked against.
String
getPlaceholder()
A hint to the user of what can be entered in the component.
String
getTitle()
The text usually displayed in a tooltip popup when the mouse is over the field.
String
getValue()
Returns the current value of the email field.
ValueChangeMode
getValueChangeMode()
Gets current value change mode of the component.
int
getValueChangeTimeout()
Returns the currently set timeout, for how often
HasValue.ValueChangeEvent
s are triggered when the ValueChangeMode is set toValueChangeMode.LAZY
, orValueChangeMode.TIMEOUT
.boolean
isAutofocus()
Specify that this control should have input focus when the page loads.
boolean
isAutoselect()
Specifies if the field value gets automatically selected when the field gains focus.
boolean
isClearButtonVisible()
Gets the visibility state of the button which clears the email field.
protected boolean
isEnforcedFieldValidationEnabled()
Whether the full experience validation is enforced for the component.
boolean
isInvalid()
Returns
true
if component input is invalid,false
otherwise.boolean
isPreventInvalidInput()
When set to
true
, user is prevented from typing a value that conflicts with the givenpattern
.protected void
onAttach(AttachEvent attachEvent)
Called when the component is attached to a UI.
void
setAutofocus(boolean autofocus)
Description copied from corresponding location in WebComponent:
void
setAutoselect(boolean autoselect)
Set to
true
to always have the field value automatically selected when the field gains focus,false
otherwise.void
setClearButtonVisible(boolean clearButtonVisible)
Set to
false
to hide the clear button which clears the email field.void
setErrorMessage(String errorMessage)
Description copied from corresponding location in WebComponent:
void
setInvalid(boolean invalid)
Description copied from corresponding location in WebComponent:
void
setLabel(String label)
Sets the label for this component.
void
setMaxLength(int maxLength)
Maximum number of characters (in Unicode code points) that the user can enter.
void
setMinLength(int minLength)
Minimum number of characters (in Unicode code points) that the user can enter.
void
setPattern(String pattern)
Description copied from corresponding location in WebComponent:
void
setPlaceholder(String placeholder)
Description copied from corresponding location in WebComponent:
void
setPreventInvalidInput(boolean preventInvalidInput)
Description copied from corresponding location in WebComponent:
void
setRequiredIndicatorVisible(boolean requiredIndicatorVisible)
Sets the required indicator visible or not.
void
setTitle(String title)
Description copied from corresponding location in WebComponent:
void
setValue(String value)
Sets the value of this email field.
void
setValueChangeMode(ValueChangeMode valueChangeMode)
Sets new value change mode for the component.
void
setValueChangeTimeout(int valueChangeTimeout)
Sets how often
HasValue.ValueChangeEvent
s are triggered when the ValueChangeMode is set toValueChangeMode.LAZY
, orValueChangeMode.TIMEOUT
.protected void
validate()
Performs server-side validation of the current value.
-
Methods inherited from class com.vaadin.flow.component.textfield.GeneratedVaadinTextField
addChangeListener, addInvalidChangeListener, addThemeVariants, addToInput, addToPrefix, addToSuffix, checkValidity, getAutocapitalizeString, getAutocompleteString, getAutocorrectString, getErrorMessageString, getLabelString, getListString, getMaxlengthDouble, getMinlengthDouble, getNameString, getPatternString, getPlaceholderString, getTitleString, isAutofocusBoolean, isAutoselectBoolean, isClearButtonVisibleBoolean, isDisabledBoolean, isInvalidBoolean, isPreventInvalidInputBoolean, isReadonlyBoolean, isRequiredBoolean, remove, removeAll, removeThemeVariants, setAutocapitalize, setAutocomplete, setAutocorrect, setDisabled, setList, setMaxlength, setMinlength, setName, setReadonly, setRequired
-
Methods inherited from class com.vaadin.flow.component.AbstractSinglePropertyField
getSynchronizationRegistration, hasValidValue, setPresentationValue, setSynchronizedEvent
-
Methods inherited from class com.vaadin.flow.component.AbstractField
addValueChangeListener, isEmpty, setModelValue, valueEquals
-
Methods inherited from class com.vaadin.flow.component.Component
addListener, fireEvent, from, get, getChildren, getElement, getEventBus, getId, getLocale, getParent, getTranslation, getTranslation, getTranslation, getTranslation, getUI, hasListener, isAttached, isTemplateMapped, isVisible, onDetach, onEnabledStateChanged, set, setElement, setId, setVisible
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.vaadin.flow.component.HasSize
getCssSize, getHeight, getHeightUnit, getMaxHeight, getMaxWidth, getMinHeight, getMinWidth, getWidth, getWidthUnit, setHeight, setHeight, setHeightFull, setMaxHeight, setMaxHeight, setMaxWidth, setMaxWidth, setMinHeight, setMinHeight, setMinWidth, setMinWidth, setSizeFull, setSizeUndefined, setWidth, setWidth, setWidthFull
-
Methods inherited from interface com.vaadin.flow.component.textfield.HasPrefixAndSuffix
getPrefixComponent, getSuffixComponent, setPrefixComponent, setSuffixComponent
-
Methods inherited from interface com.vaadin.flow.component.InputNotifier
addInputListener
-
Methods inherited from interface com.vaadin.flow.component.KeyNotifier
addKeyDownListener, addKeyDownListener, addKeyPressListener, addKeyPressListener, addKeyUpListener, addKeyUpListener
-
Methods inherited from interface com.vaadin.flow.component.CompositionNotifier
addCompositionEndListener, addCompositionStartListener, addCompositionUpdateListener
-
Methods inherited from interface com.vaadin.flow.component.textfield.HasAutocomplete
getAutocomplete, setAutocomplete
-
Methods inherited from interface com.vaadin.flow.component.textfield.HasAutocapitalize
getAutocapitalize, setAutocapitalize
-
Methods inherited from interface com.vaadin.flow.component.textfield.HasAutocorrect
isAutocorrect, setAutocorrect
-
Methods inherited from interface com.vaadin.flow.component.HasHelper
getHelperComponent, getHelperText, setHelperComponent, setHelperText
-
Methods inherited from interface com.vaadin.flow.component.HasElement
getElement
-
Methods inherited from interface com.vaadin.flow.component.shared.HasClientValidation
addClientValidatedEventListener
-
Methods inherited from interface com.vaadin.flow.component.HasStyle
addClassName, addClassNames, getClassName, getClassNames, getStyle, hasClassName, removeClassName, removeClassNames, setClassName, setClassName
-
Methods inherited from interface com.vaadin.flow.component.Focusable
addFocusShortcut, blur, focus, getTabIndex, setTabIndex
-
Methods inherited from interface com.vaadin.flow.component.BlurNotifier
addBlurListener
-
Methods inherited from interface com.vaadin.flow.component.FocusNotifier
addFocusListener
-
Methods inherited from interface com.vaadin.flow.component.HasEnabled
isEnabled, setEnabled
-
Methods inherited from interface com.vaadin.flow.component.HasTheme
addThemeName, addThemeNames, getThemeName, getThemeNames, hasThemeName, removeThemeName, removeThemeNames, setThemeName, setThemeName
-
Methods inherited from interface com.vaadin.flow.component.HasValueAndElement
isReadOnly, isRequiredIndicatorVisible, setReadOnly
-
Methods inherited from interface com.vaadin.flow.component.HasValue
clear, getOptionalValue
-
Methods inherited from interface com.vaadin.flow.component.AttachNotifier
addAttachListener
-
Methods inherited from interface com.vaadin.flow.component.DetachNotifier
addDetachListener
-
-
-
-
Constructor Detail
-
EmailField
public EmailField()
Constructs an empty
EmailField
.
-
EmailField
public EmailField(String label)
Constructs an empty
EmailField
with the given label.Parameters:
label
- the text to set as the label
-
EmailField
public EmailField(String label, String placeholder)
Constructs an empty
EmailField
with the given label and placeholder text.Parameters:
label
- the text to set as the labelplaceholder
- the placeholder text to set
-
EmailField
public EmailField(HasValue.ValueChangeListener<? super AbstractField.ComponentValueChangeEvent<EmailField,String>> listener)
Constructs an empty
EmailField
with a value change listener.Parameters:
listener
- the value change listenerSee Also:
AbstractField.addValueChangeListener(com.vaadin.flow.component.HasValue.ValueChangeListener)
-
EmailField
public EmailField(String label, HasValue.ValueChangeListener<? super AbstractField.ComponentValueChangeEvent<EmailField,String>> listener)
Constructs an empty
EmailField
with a value change listener and a label.Parameters:
label
- the text to set as the labellistener
- the value change listenerSee Also:
setLabel(String)
,AbstractField.addValueChangeListener(com.vaadin.flow.component.HasValue.ValueChangeListener)
-
EmailField
public EmailField(String label, String initialValue, HasValue.ValueChangeListener<? super AbstractField.ComponentValueChangeEvent<EmailField,String>> listener)
Constructs a
EmailField
with a value change listener, a label and an initial value.Parameters:
label
- the text to set as the labelinitialValue
- the initial valuelistener
- the value change listenerSee Also:
setLabel(String)
,AbstractField.setValue(Object)
,AbstractField.addValueChangeListener(com.vaadin.flow.component.HasValue.ValueChangeListener)
-
-
Method Detail
-
getValueChangeMode
public ValueChangeMode getValueChangeMode()
Gets current value change mode of the component.
The default value is
ValueChangeMode.ON_CHANGE
.Specified by:
getValueChangeMode
in interfaceHasValueChangeMode
Returns:
current value change mode of the component, or
null
if the value is not synchronized
-
setValueChangeMode
public void setValueChangeMode(ValueChangeMode valueChangeMode)
Description copied from interface:
HasValueChangeMode
Sets new value change mode for the component.
Specified by:
setValueChangeMode
in interfaceHasValueChangeMode
Parameters:
valueChangeMode
- new value change mode, ornull
to disable the value synchronization
-
setValueChangeTimeout
public void setValueChangeTimeout(int valueChangeTimeout)
Description copied from interface:
HasValueChangeMode
Sets how often
HasValue.ValueChangeEvent
s are triggered when the ValueChangeMode is set toValueChangeMode.LAZY
, orValueChangeMode.TIMEOUT
.Implementations should use
ValueChangeMode.applyChangeTimeout(ValueChangeMode, int, DomListenerRegistration)
.Specified by:
setValueChangeTimeout
in interfaceHasValueChangeMode
Parameters:
valueChangeTimeout
- the timeout in milliseconds of how oftenHasValue.ValueChangeEvent
s are triggered.
-
getValueChangeTimeout
public int getValueChangeTimeout()
Description copied from interface:
HasValueChangeMode
Returns the currently set timeout, for how often
HasValue.ValueChangeEvent
s are triggered when the ValueChangeMode is set toValueChangeMode.LAZY
, orValueChangeMode.TIMEOUT
.Specified by:
getValueChangeTimeout
in interfaceHasValueChangeMode
Returns:
the timeout in milliseconds of how often
HasValue.ValueChangeEvent
s are triggered.
-
getErrorMessage
public String getErrorMessage()
Description copied from interface:
HasValidation
Gets current error message from the component.
Specified by:
getErrorMessage
in interfaceHasValidation
Returns:
current error message
-
setErrorMessage
public void setErrorMessage(String errorMessage)
Description copied from class:
GeneratedVaadinTextField
Description copied from corresponding location in WebComponent:
Error to show when the input value is invalid.
Specified by:
setErrorMessage
in interfaceHasValidation
Overrides:
setErrorMessage
in classGeneratedVaadinTextField<EmailField,String>
Parameters:
errorMessage
- the String value to set
-
isInvalid
public boolean isInvalid()
Description copied from interface:
HasValidation
Returns
true
if component input is invalid,false
otherwise.Specified by:
isInvalid
in interfaceHasValidation
Returns:
whether the component input is valid
-
setInvalid
public void setInvalid(boolean invalid)
Description copied from class:
GeneratedVaadinTextField
Description copied from corresponding location in WebComponent:
This property is set to true when the control value is invalid.
Specified by:
setInvalid
in interfaceHasValidation
Overrides:
setInvalid
in classGeneratedVaadinTextField<EmailField,String>
Parameters:
invalid
- the boolean value to set
-
setLabel
public void setLabel(String label)
Sets the label for this component.
Specified by:
setLabel
in interfaceHasLabel
Overrides:
setLabel
in classGeneratedVaadinTextField<EmailField,String>
Parameters:
label
- value for thelabel
property in the webcomponent
-
getLabel
public String getLabel()
String used for the label element.
-
setPlaceholder
public void setPlaceholder(String placeholder)
Description copied from class:
GeneratedVaadinTextField
Description copied from corresponding location in WebComponent:
A hint to the user of what can be entered in the control.
Overrides:
setPlaceholder
in classGeneratedVaadinTextField<EmailField,String>
Parameters:
placeholder
- the String value to set
-
getPlaceholder
public String getPlaceholder()
A hint to the user of what can be entered in the component.
Returns:
the
placeholder
property from the webcomponent
-
setAutofocus
public void setAutofocus(boolean autofocus)
Description copied from class:
GeneratedVaadinTextField
Description copied from corresponding location in WebComponent:
Specify that this control should have input focus when the page loads.
Overrides:
setAutofocus
in classGeneratedVaadinTextField<EmailField,String>
Parameters:
autofocus
- the boolean value to set
-
isAutofocus
public boolean isAutofocus()
Specify that this control should have input focus when the page loads.
Returns:
the
autofocus
property from the webcomponent
-
setMaxLength
public void setMaxLength(int maxLength)
Maximum number of characters (in Unicode code points) that the user can enter.
Parameters:
maxLength
- the maximum length
-
getMaxLength
public int getMaxLength()
Maximum number of characters (in Unicode code points) that the user can enter.
Returns:
the
maxlength
property from the webcomponent
-
setMinLength
public void setMinLength(int minLength)
Minimum number of characters (in Unicode code points) that the user can enter.
Parameters:
minLength
- the minimum length
-
getMinLength
public int getMinLength()
Minimum number of characters (in Unicode code points) that the user can enter.
Returns:
the
minlength
property from the webcomponent
-
isPreventInvalidInput
public boolean isPreventInvalidInput()
When set to
true
, user is prevented from typing a value that conflicts with the givenpattern
.Returns:
the
preventInvalidInput
property from the webcomponent
-
setPreventInvalidInput
public void setPreventInvalidInput(boolean preventInvalidInput)
Description copied from class:
GeneratedVaadinTextField
Description copied from corresponding location in WebComponent:
When set to true, user is prevented from typing a value that conflicts with the given
pattern
,maxlength
orminlength
properties.Overrides:
setPreventInvalidInput
in classGeneratedVaadinTextField<EmailField,String>
Parameters:
preventInvalidInput
- the boolean value to set
-
setPattern
public void setPattern(String pattern)
Description copied from class:
GeneratedVaadinTextField
Description copied from corresponding location in WebComponent:
A regular expression that the value is checked against. The pattern must match the entire value, not just some subset.
Overrides:
setPattern
in classGeneratedVaadinTextField<EmailField,String>
Parameters:
pattern
- the String value to set
-
getPattern
public String getPattern()
A regular expression that the value is checked against. The pattern must match the entire value, not just some subset.
Returns:
the
pattern
property from the webcomponent
-
getTitle
public String getTitle()
The text usually displayed in a tooltip popup when the mouse is over the field.
Returns:
the
title
property from the webcomponent
-
setTitle
public void setTitle(String title)
Description copied from class:
GeneratedVaadinTextField
Description copied from corresponding location in WebComponent:
The text usually displayed in a tooltip popup when the mouse is over the field.
Overrides:
setTitle
in classGeneratedVaadinTextField<EmailField,String>
Parameters:
title
- the String value to set
-
isAutoselect
public boolean isAutoselect()
Specifies if the field value gets automatically selected when the field gains focus.
Returns:
true
if autoselect is active,false
otherwise
-
setAutoselect
public void setAutoselect(boolean autoselect)
Set to
true
to always have the field value automatically selected when the field gains focus,false
otherwise.Overrides:
setAutoselect
in classGeneratedVaadinTextField<EmailField,String>
Parameters:
autoselect
-true
to set auto select on,false
otherwise
-
isClearButtonVisible
public boolean isClearButtonVisible()
Gets the visibility state of the button which clears the email field.
Returns:
true
if the button is visible,false
otherwise
-
setClearButtonVisible
public void setClearButtonVisible(boolean clearButtonVisible)
Set to
false
to hide the clear button which clears the email field.Overrides:
setClearButtonVisible
in classGeneratedVaadinTextField<EmailField,String>
Parameters:
clearButtonVisible
-true
to set the button visible,false
otherwise
-
getEmptyValue
public String getEmptyValue()
Description copied from interface:
HasValue
Returns the value that represents an empty value.
By default
HasValue
is expected to supportnull
as empty values. Specific implementations might not support this.Specified by:
getEmptyValue
in interfaceHasValue<AbstractField.ComponentValueChangeEvent<EmailField,String>,String>
Overrides:
getEmptyValue
in classAbstractField<EmailField,String>
Returns:
empty value
-
setValue
public void setValue(String value)
Sets the value of this email field. If the new value is not equal to
getValue()
, fires a value change event. ThrowsNullPointerException
, if the value is null.Note:
Binder
will take care of thenull
conversion when integrates with email field, as long as no new converter is defined.Specified by:
setValue
in interfaceHasValue<AbstractField.ComponentValueChangeEvent<EmailField,String>,String>
Overrides:
setValue
in classAbstractField<EmailField,String>
Parameters:
value
- the new value, notnull
-
getValue
public String getValue()
Returns the current value of the email field. By default, the empty email field will return an empty string.
Specified by:
getValue
in interfaceHasValue<AbstractField.ComponentValueChangeEvent<EmailField,String>,String>
Overrides:
getValue
in classAbstractField<EmailField,String>
Returns:
the current value.
-
setRequiredIndicatorVisible
public void setRequiredIndicatorVisible(boolean requiredIndicatorVisible)
Description copied from interface:
HasValue
Sets the required indicator visible or not.
If set visible, it is visually indicated in the user interface.
The method is intended to be used with
Binder
which does server-side validation. In case HTML element has its own (client-side) validation it should be disabled whensetRequiredIndicatorVisible(true)
is called and re-enabled back onsetRequiredIndicatorVisible(false)
. It's responsibility of each component implementation to follow the contract so that the method call doesn't do anything else than show/hide the "required" indication. Usually components provide their ownsetRequired
method which should be called in case the client-side validation is required.Specified by:
setRequiredIndicatorVisible
in interfaceHasValue<AbstractField.ComponentValueChangeEvent<EmailField,String>,String>
Specified by:
setRequiredIndicatorVisible
in interfaceHasValueAndElement<AbstractField.ComponentValueChangeEvent<EmailField,String>,String>
Parameters:
requiredIndicatorVisible
-true
to make the required indicator visible,false
if not
-
getDefaultValidator
public Validator<String> getDefaultValidator()
Description copied from interface:
HasValidator
Returns a validator that checks the state of the Value. This should be overridden for components with internal value conversion or validation, e.g. when the user is providing a string that has to be parsed into a date. An invalid input from user will be exposed to a
Binder
and can be seen as a validation failure.Specified by:
getDefaultValidator
in interfaceHasValidator<String>
Returns:
state validator
-
addValidationStatusChangeListener
public Registration addValidationStatusChangeListener(ValidationStatusChangeListener<String> listener)
Description copied from interface:
HasValidator
Enables the implementing components to notify changes in their validation status to the observers.
Note: This method can be overridden by the implementing classes e.g. components, to enable the associated
Binder.Binding
instance subscribing for their validation change events and revalidate itself.This method primarily designed for notifying the Binding about the validation status changes of a bound component at the client-side. WebComponents such as
<vaadin-date-picker>
or any other component that accept a formatted text as input should be able to communicate their invalid status to their server-side instance, and a bound server-side component instance must notify its binding about this validation status change as well. When the binding instance revalidates, a chain of validators and convertors get executed one of which is the default validator provided byHasValidator.getDefaultValidator()
. Thus, In order for the binding to be able to show/clear errors for its associated bound field, it is important that implementing components take that validation status into account while implementing any validator and converter includingHasValidator.getDefaultValidator()
. Here is an example:@Tag("date-picker-demo") public class DatePickerDemo implements HasValidator<LocalDate> { // Each web component has a way to communicate its validation status // to its server-side component instance. The following clientSideValid // state is introduced here just for the sake of simplicity of this code // snippet: boolean clientSideValid = true; /** * Note how
clientSideValid
engaged in the definition * of this method. It is important to reflect this status either * in the returning validation result of this method or any other * validation that is associated with this component. */ @Override public Validator getDefaultValidator() { return (value, valueContext) -> clientSideValid ? ValidationResult.ok() : ValidationResult.error("Invalid date format"); } private final Collection<ValidationStatusChangeListener<LocalDate>> validationStatusListeners = new ArrayList<>(); /** * This enables the binding to subscribe for the validation status * change events that are fired by this component and revalidate * itself respectively. */ @Override public Registration addValidationStatusChangeListener( ValidationStatusChangeListener<LocalDate> listener) { validationStatusListeners.add(listener); return () -> validationStatusListeners.remove(listener); } private void fireValidationStatusChangeEvent( boolean newValidationStatus) { if (this.clientSideValid != newValidationStatus) { this.clientSideValid = newValidationStatus; var event = new ValidationStatusChangeEvent<>(this, newValidationStatus); validationStatusListeners.forEach( listener -> listener.validationStatusChanged(event)); } } }Specified by:
addValidationStatusChangeListener
in interfaceHasValidator<String>
Returns:
Registration of the added listener.
See Also:
-
validate
protected void validate()
Performs server-side validation of the current value. This is needed because it is possible to circumvent the client-side validation constraints using browser development tools.
Overrides:
validate
in classGeneratedVaadinTextField<EmailField,String>
-
onAttach
protected void onAttach(AttachEvent attachEvent)
Description copied from class:
Component
Called when the component is attached to a UI.
The default implementation does nothing.
This method is invoked before the
AttachEvent
is fired for the component.
-
isEnforcedFieldValidationEnabled
protected boolean isEnforcedFieldValidationEnabled()
Whether the full experience validation is enforced for the component.
Exposed with protected visibility to support mocking
The method requires the
VaadinSession
instance to obtain the application configuration properties, otherwise, the feature is considered disabled.Returns:
true
if enabled,false
otherwise.
-
-