com.vaadin.flow.component.textfield.
Class AbstractNumberField<C extends AbstractNumberField<C,T>,T extends Number>
- 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.GeneratedVaadinNumberField<C,T>
-
- com.vaadin.flow.component.textfield.AbstractNumberField<C,T>
-
All Implemented Interfaces:
AttachNotifier
,BlurNotifier<C>
,CompositionNotifier
,DetachNotifier
,Focusable<C>
,FocusNotifier<C>
,HasElement
,HasEnabled
,HasHelper
,HasLabel
,HasSize
,HasStyle
,HasTheme
,HasValidation
,HasValue<AbstractField.ComponentValueChangeEvent<C,T>,T>
,HasValueAndElement<AbstractField.ComponentValueChangeEvent<C,T>,T>
,InputNotifier
,KeyNotifier
,HasClearButton
,HasAutocapitalize
,HasAutocomplete
,HasAutocorrect
,HasPrefixAndSuffix
,HasValueChangeMode
,Serializable
Direct Known Subclasses:
public abstract class AbstractNumberField<C extends AbstractNumberField<C,T>,T extends Number> extends GeneratedVaadinNumberField<C,T> implements HasSize, HasValidation, HasValueChangeMode, HasPrefixAndSuffix, InputNotifier, KeyNotifier, CompositionNotifier, HasAutocomplete, HasAutocapitalize, HasAutocorrect, HasHelper, HasLabel, HasClearButton
Abstract base class for components based on
vaadin-number-field
element and its subclasses.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.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.component.textfield.HasAutocapitalize
AUTOCAPITALIZE_ATTRIBUTE
-
Fields inherited from interface com.vaadin.flow.component.textfield.HasAutocomplete
AUTOCOMPLETE_ATTRIBUTE
-
Fields inherited from interface com.vaadin.flow.component.textfield.HasAutocorrect
AUTOCORRECT_ATTRIBUTE
-
Fields inherited from interface com.vaadin.flow.data.value.HasValueChangeMode
DEFAULT_CHANGE_TIMEOUT
-
-
Constructor Summary
Constructors Constructor Description AbstractNumberField(SerializableFunction<String,T> parser, SerializableFunction<T,String> formatter, double absoluteMin, double absoluteMax)
Sets up the common logic for number fields.
AbstractNumberField(SerializableFunction<String,T> parser, SerializableFunction<T,String> formatter, double absoluteMin, double absoluteMax, boolean isInitialValueOptional)
Sets up the common logic for number fields.
-
Method Summary
All Methods Modifier and Type Method Description T
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.
protected double
getMaxDouble()
Description copied from corresponding location in WebComponent:
protected double
getMinDouble()
Description copied from corresponding location in WebComponent:
String
getPlaceholder()
A hint to the user of what can be entered in the component.
protected double
getStepDouble()
Description copied from corresponding location in WebComponent:
String
getTitle()
The text usually displayed in a tooltip popup when the mouse is over the field.
T
getValue()
Returns the current value of the number 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
hasControls()
Gets whether the control buttons for increasing/decreasing the value are visible.
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
isInvalid()
Returns
true
if component input is invalid,false
otherwise.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
setErrorMessage(String errorMessage)
Description copied from corresponding location in WebComponent:
void
setHasControls(boolean hasControls)
Sets the visibility of the control buttons for increasing/decreasing the value accordingly to the default or specified step.
void
setInvalid(boolean invalid)
Description copied from corresponding location in WebComponent:
void
setLabel(String label)
Description copied from corresponding location in WebComponent:
protected void
setMax(double max)
Description copied from corresponding location in WebComponent:
protected void
setMin(double min)
Description copied from corresponding location in WebComponent:
void
setPlaceholder(String placeholder)
Description copied from corresponding location in WebComponent:
void
setRequiredIndicatorVisible(boolean requiredIndicatorVisible)
Sets the required indicator visible or not.
protected void
setStep(double step)
Description copied from corresponding location in WebComponent:
void
setTitle(String title)
Description copied from corresponding location in WebComponent:
void
setValue(T value)
Sets the value of this number 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.GeneratedVaadinNumberField
checkValidity, hasControlsBoolean
-
Methods inherited from class com.vaadin.flow.component.textfield.GeneratedVaadinTextField
addChangeListener, addInvalidChangeListener, addThemeVariants, addToInput, addToPrefix, addToSuffix, getAutocapitalizeString, getAutocompleteString, getAutocorrectString, getErrorMessageString, getLabelString, getListString, getMaxlengthDouble, getMinlengthDouble, getNameString, getPatternString, getPlaceholderString, getTitleString, isAutofocusBoolean, isAutoselectBoolean, isDisabledBoolean, isInvalidBoolean, isPreventInvalidInputBoolean, isReadonlyBoolean, isRequiredBoolean, remove, removeAll, removeThemeVariants, setAutocapitalize, setAutocomplete, setAutocorrect, setDisabled, setList, setMaxlength, setMinlength, setName, setPattern, setPreventInvalidInput, 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, getUI, hasListener, isAttached, isTemplateMapped, isVisible, onDetach, onEnabledStateChanged, scrollIntoView, 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.AttachNotifier
addAttachListener
-
Methods inherited from interface com.vaadin.flow.component.BlurNotifier
addBlurListener
-
Methods inherited from interface com.vaadin.flow.component.CompositionNotifier
addCompositionEndListener, addCompositionStartListener, addCompositionUpdateListener
-
Methods inherited from interface com.vaadin.flow.component.DetachNotifier
addDetachListener
-
Methods inherited from interface com.vaadin.flow.component.Focusable
addFocusShortcut, blur, focus, getTabIndex, setTabIndex
-
Methods inherited from interface com.vaadin.flow.component.FocusNotifier
addFocusListener
-
Methods inherited from interface com.vaadin.flow.component.textfield.HasAutocapitalize
getAutocapitalize, setAutocapitalize
-
Methods inherited from interface com.vaadin.flow.component.textfield.HasAutocomplete
getAutocomplete, setAutocomplete
-
Methods inherited from interface com.vaadin.flow.component.textfield.HasAutocorrect
isAutocorrect, setAutocorrect
-
Methods inherited from interface com.vaadin.flow.component.shared.HasClearButton
isClearButtonVisible, setClearButtonVisible
-
Methods inherited from interface com.vaadin.flow.component.HasElement
getElement
-
Methods inherited from interface com.vaadin.flow.component.HasEnabled
isEnabled, setEnabled
-
Methods inherited from interface com.vaadin.flow.component.HasHelper
getHelperComponent, getHelperText, setHelperComponent, setHelperText
-
Methods inherited from interface com.vaadin.flow.component.textfield.HasPrefixAndSuffix
getPrefixComponent, getSuffixComponent, setPrefixComponent, setSuffixComponent
-
Methods inherited from interface com.vaadin.flow.component.HasSize
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.HasStyle
addClassName, addClassNames, getClassName, getClassNames, getStyle, hasClassName, removeClassName, removeClassNames, setClassName, setClassName
-
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.HasValue
clear, getOptionalValue
-
Methods inherited from interface com.vaadin.flow.component.HasValueAndElement
isReadOnly, isRequiredIndicatorVisible, setReadOnly
-
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
-
-
-
-
Constructor Detail
-
AbstractNumberField
public AbstractNumberField(SerializableFunction<String,T> parser, SerializableFunction<T,String> formatter, double absoluteMin, double absoluteMax, boolean isInitialValueOptional)
Sets up the common logic for number fields.
If
isInitialValueOptional
istrue
then the initial value is used only if element has no"value"
property value, otherwise element"value"
property is ignored and the initial value is set.Parameters:
parser
- function to parse the client-side value string into server-side valueformatter
- function to format the server-side value into client-side value stringabsoluteMin
- the smallest possible value of the number type of the field, will be used as the default min value at server-sideabsoluteMax
- the largest possible value of the number type of the field, will be used as the default max value at server-sideisInitialValueOptional
- ifisInitialValueOptional
istrue
then the initial value is used only if element has no"value"
property value, otherwise element"value"
property is ignored and the initial value is set
-
AbstractNumberField
public AbstractNumberField(SerializableFunction<String,T> parser, SerializableFunction<T,String> formatter, double absoluteMin, double absoluteMax)
Sets up the common logic for number fields.
Parameters:
parser
- function to parse the client-side value string into server-side valueformatter
- function to format the server-side value into client-side value stringabsoluteMin
- the smallest possible value of the number type of the field, will be used as the default min value at server-sideabsoluteMax
- the largest possible value of the number type of the field, will be used as the default max value at server-side
-
-
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<C extends AbstractNumberField<C,T>,T extends Number>
Parameters:
errorMessage
- the String value to set
-
setLabel
public void setLabel(String label)
Description copied from class:
GeneratedVaadinTextField
Description copied from corresponding location in WebComponent:
String used for the label element.
Specified by:
setLabel
in interfaceHasLabel
Overrides:
setLabel
in classGeneratedVaadinTextField<C extends AbstractNumberField<C,T>,T extends Number>
Parameters:
label
- the String value to set
-
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<C extends AbstractNumberField<C,T>,T extends Number>
Parameters:
placeholder
- the String value to set
-
setHasControls
public void setHasControls(boolean hasControls)
Sets the visibility of the control buttons for increasing/decreasing the value accordingly to the default or specified step.
Overrides:
setHasControls
in classGeneratedVaadinNumberField<C extends AbstractNumberField<C,T>,T extends Number>
Parameters:
hasControls
-true
if control buttons should be visible;false
if those should be hiddenSee Also:
-
hasControls
public boolean hasControls()
Gets whether the control buttons for increasing/decreasing the value are visible.
Returns:
true
if buttons are visible,false
otherwiseSee Also:
-
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<C extends AbstractNumberField<C,T>,T extends Number>
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
-
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<C extends AbstractNumberField<C,T>,T extends Number>
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<C extends AbstractNumberField<C,T>,T extends Number>
Parameters:
autoselect
-true
to set auto select on,false
otherwise
-
getEmptyValue
public T getEmptyValue()
Returns the value that represents an empty value.
Specified by:
getEmptyValue
in interfaceHasValue<C extends AbstractNumberField<C,T>,T extends Number>
Overrides:
getEmptyValue
in classAbstractField<C extends AbstractNumberField<C,T>,T extends Number>
Returns:
empty value
-
setValue
public void setValue(T value)
Sets the value of this number field. If the new value is not equal to
getValue()
, fires a value change event.
-
getValue
public T getValue()
Returns the current value of the number field. By default, the empty number field will return
null
.
-
setMin
protected void setMin(double min)
Description copied from class:
GeneratedVaadinNumberField
Description copied from corresponding location in WebComponent:
The minimum value of the field.
Overrides:
setMin
in classGeneratedVaadinNumberField<C extends AbstractNumberField<C,T>,T extends Number>
Parameters:
min
- the double value to set
-
getMinDouble
protected double getMinDouble()
Description copied from class:
GeneratedVaadinNumberField
Description copied from corresponding location in WebComponent:
The minimum value of the field.
This property is not synchronized automatically from the client side, so the returned value may not be the same as in client side.
Overrides:
getMinDouble
in classGeneratedVaadinNumberField<C extends AbstractNumberField<C,T>,T extends Number>
Returns:
the
min
property from the webcomponent
-
setMax
protected void setMax(double max)
Description copied from class:
GeneratedVaadinNumberField
Description copied from corresponding location in WebComponent:
The maximum value of the field.
Overrides:
setMax
in classGeneratedVaadinNumberField<C extends AbstractNumberField<C,T>,T extends Number>
Parameters:
max
- the double value to set
-
getMaxDouble
protected double getMaxDouble()
Description copied from class:
GeneratedVaadinNumberField
Description copied from corresponding location in WebComponent:
The maximum value of the field.
This property is not synchronized automatically from the client side, so the returned value may not be the same as in client side.
Overrides:
getMaxDouble
in classGeneratedVaadinNumberField<C extends AbstractNumberField<C,T>,T extends Number>
Returns:
the
max
property from the webcomponent
-
setStep
protected void setStep(double step)
Description copied from class:
GeneratedVaadinNumberField
Description copied from corresponding location in WebComponent:
Specifies the allowed number intervals of the field.
Overrides:
setStep
in classGeneratedVaadinNumberField<C extends AbstractNumberField<C,T>,T extends Number>
Parameters:
step
- the double value to set
-
getStepDouble
protected double getStepDouble()
Description copied from class:
GeneratedVaadinNumberField
Description copied from corresponding location in WebComponent:
Specifies the allowed number intervals of the field.
This property is not synchronized automatically from the client side, so the returned value may not be the same as in client side.
Overrides:
getStepDouble
in classGeneratedVaadinNumberField<C extends AbstractNumberField<C,T>,T extends Number>
Returns:
the
step
property from the webcomponent
-
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<C extends AbstractNumberField<C,T>,T extends Number>
Parameters:
invalid
- the boolean 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
-
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<C extends AbstractNumberField<C,T>,T extends Number>
-
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<C extends AbstractNumberField<C,T>,T extends Number>
Specified by:
setRequiredIndicatorVisible
in interfaceHasValueAndElement<C extends AbstractNumberField<C,T>,T extends Number>
Parameters:
requiredIndicatorVisible
-true
to make the required indicator visible,false
if not
-
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.
-
-