@Tag(value="vaadin-big-decimal-field") @JavaScript(value="frontend://vaadin-big-decimal-field.js") @JsModule(value="./vaadin-big-decimal-field.js") public class BigDecimalField extends GeneratedVaadinTextField<BigDecimalField,BigDecimal> implements HasSize, HasValidation, HasValueChangeMode, HasPrefixAndSuffix, InputNotifier, KeyNotifier, CompositionNotifier, HasAutocomplete, HasAutocapitalize, HasAutocorrect, HasHelper, HasLabel, HasValidator<BigDecimal>, HasClientValidation
vaadin-big-decimal-field
element. This
field uses BigDecimal
as the server-side value type, which allows
handling decimal numbers with high precision. The component also prevents
users from entering characters which can't be used in a decimal number, such
as alphabets.
When setting values from the server-side, the scale
of the provided
BigDecimal
is preserved in the presentation format shown to the user,
as described in setValue(BigDecimal)
.
GeneratedVaadinTextField.ChangeEvent<R extends GeneratedVaadinTextField<R,?>>, GeneratedVaadinTextField.InvalidChangeEvent<R extends GeneratedVaadinTextField<R,?>>
AbstractField.ComponentValueChangeEvent<C extends Component,V>
HasClientValidation.ClientValidatedEvent
BlurNotifier.BlurEvent<C extends Component>
FocusNotifier.FocusEvent<C extends Component>
HasValue.ValueChangeEvent<V>, HasValue.ValueChangeListener<E extends HasValue.ValueChangeEvent<?>>
DEFAULT_CHANGE_TIMEOUT
AUTOCOMPLETE_ATTRIBUTE
AUTOCAPITALIZE_ATTRIBUTE
AUTOCORRECT_ATTRIBUTE
Constructor and Description |
---|
BigDecimalField()
Constructs an empty
BigDecimalField . |
BigDecimalField(HasValue.ValueChangeListener<? super AbstractField.ComponentValueChangeEvent<BigDecimalField,BigDecimal>> listener)
Constructs an empty
BigDecimalField with a value change listener. |
BigDecimalField(String label)
Constructs an empty
BigDecimalField with the given label. |
BigDecimalField(String label,
BigDecimal initialValue,
HasValue.ValueChangeListener<? super AbstractField.ComponentValueChangeEvent<BigDecimalField,BigDecimal>> listener)
Constructs an empty
BigDecimalField with a label,a value change
listener and an initial value. |
BigDecimalField(String label,
BigDecimal initialValue,
String placeholder)
Constructs a
BigDecimalField with the given label, an initial
value and placeholder text. |
BigDecimalField(String label,
HasValue.ValueChangeListener<? super AbstractField.ComponentValueChangeEvent<BigDecimalField,BigDecimal>> listener)
Constructs an empty
BigDecimalField with a label and a value
change listener. |
BigDecimalField(String label,
String placeholder)
Constructs an empty
BigDecimalField with the given label and
placeholder text. |
Modifier and Type | Method and Description |
---|---|
Registration |
addValidationStatusChangeListener(ValidationStatusChangeListener<BigDecimal> listener)
Enables the implementing components to notify changes in their validation
status to the observers.
|
Validator<BigDecimal> |
getDefaultValidator()
Returns a validator that checks the state of the Value.
|
BigDecimal |
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.
|
Locale |
getLocale()
Gets the locale used by this BigDecimalField.
|
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.
|
BigDecimal |
getValue()
Returns the current value of the 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
to ValueChangeMode.LAZY , or ValueChangeMode.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 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. |
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 text
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 |
setLocale(Locale locale)
Sets the locale for this BigDecimalField.
|
void |
setPlaceholder(String placeholder)
Description copied from corresponding location in WebComponent:
|
void |
setTitle(String title)
Description copied from corresponding location in WebComponent:
|
void |
setValue(BigDecimal value)
Sets the value of this 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 to ValueChangeMode.LAZY , or
ValueChangeMode.TIMEOUT . |
protected void |
validate()
Performs server-side validation of the current value.
|
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, setPattern, setPreventInvalidInput, setReadonly, setRequired
getSynchronizationRegistration, hasValidValue, setPresentationValue, setSynchronizedEvent
addValueChangeListener, isEmpty, setModelValue, valueEquals
addListener, fireEvent, from, get, getChildren, getElement, getEventBus, getId, getParent, getTranslation, getTranslation, getTranslation, getTranslation, getUI, hasListener, isAttached, isTemplateMapped, isVisible, onDetach, onEnabledStateChanged, set, setElement, setId, setVisible
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
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
getPrefixComponent, getSuffixComponent, setPrefixComponent, setSuffixComponent
addInputListener
addKeyDownListener, addKeyDownListener, addKeyPressListener, addKeyPressListener, addKeyUpListener, addKeyUpListener
addCompositionEndListener, addCompositionStartListener, addCompositionUpdateListener
getAutocomplete, setAutocomplete
getAutocapitalize, setAutocapitalize
isAutocorrect, setAutocorrect
getHelperComponent, getHelperText, setHelperComponent, setHelperText
getElement
addClientValidatedEventListener
addClassName, addClassNames, getClassName, getClassNames, getStyle, hasClassName, removeClassName, removeClassNames, setClassName, setClassName
addFocusShortcut, blur, focus, getTabIndex, setTabIndex
addBlurListener
addFocusListener
isEnabled, setEnabled
addThemeName, addThemeNames, getThemeName, getThemeNames, hasThemeName, removeThemeName, removeThemeNames, setThemeName, setThemeName
isReadOnly, isRequiredIndicatorVisible, setReadOnly, setRequiredIndicatorVisible
clear, getOptionalValue
addAttachListener
addDetachListener
public BigDecimalField()
BigDecimalField
.public BigDecimalField(String label)
BigDecimalField
with the given label.label
- the text to set as the labelpublic BigDecimalField(String label, String placeholder)
BigDecimalField
with the given label and
placeholder text.label
- the text to set as the labelplaceholder
- the placeholder text to setpublic BigDecimalField(String label, BigDecimal initialValue, String placeholder)
BigDecimalField
with the given label, an initial
value and placeholder text.label
- the text to set as the labelinitialValue
- the initial valueplaceholder
- the placeholder text to setAbstractField.setValue(Object)
,
setPlaceholder(String)
public BigDecimalField(HasValue.ValueChangeListener<? super AbstractField.ComponentValueChangeEvent<BigDecimalField,BigDecimal>> listener)
BigDecimalField
with a value change listener.listener
- the value change listenerAbstractField.addValueChangeListener(com.vaadin.flow.component.HasValue.ValueChangeListener)
public BigDecimalField(String label, HasValue.ValueChangeListener<? super AbstractField.ComponentValueChangeEvent<BigDecimalField,BigDecimal>> listener)
BigDecimalField
with a label and a value
change listener.label
- the text to set as the labellistener
- the value change listenersetLabel(String)
,
AbstractField.addValueChangeListener(com.vaadin.flow.component.HasValue.ValueChangeListener)
public BigDecimalField(String label, BigDecimal initialValue, HasValue.ValueChangeListener<? super AbstractField.ComponentValueChangeEvent<BigDecimalField,BigDecimal>> listener)
BigDecimalField
with a label,a value change
listener and an initial value.label
- the text to set as the labelinitialValue
- the initial valuelistener
- the value change listenersetLabel(String)
,
AbstractField.setValue(Object)
,
AbstractField.addValueChangeListener(com.vaadin.flow.component.HasValue.ValueChangeListener)
public ValueChangeMode getValueChangeMode()
The default value is ValueChangeMode.ON_CHANGE
.
getValueChangeMode
in interface HasValueChangeMode
null
if
the value is not synchronizedpublic void setValueChangeMode(ValueChangeMode valueChangeMode)
HasValueChangeMode
setValueChangeMode
in interface HasValueChangeMode
valueChangeMode
- new value change mode, or null
to disable the value
synchronizationpublic void setValueChangeTimeout(int valueChangeTimeout)
HasValueChangeMode
HasValue.ValueChangeEvent
s are triggered when the
ValueChangeMode is set to ValueChangeMode.LAZY
, or
ValueChangeMode.TIMEOUT
.
Implementations should use
ValueChangeMode.applyChangeTimeout(ValueChangeMode, int, DomListenerRegistration)
.
setValueChangeTimeout
in interface HasValueChangeMode
valueChangeTimeout
- the timeout in milliseconds of how often
HasValue.ValueChangeEvent
s are triggered.public int getValueChangeTimeout()
HasValueChangeMode
HasValue.ValueChangeEvent
s are triggered when the ValueChangeMode is set
to ValueChangeMode.LAZY
, or ValueChangeMode.TIMEOUT
.getValueChangeTimeout
in interface HasValueChangeMode
HasValue.ValueChangeEvent
s are triggered.public String getErrorMessage()
HasValidation
getErrorMessage
in interface HasValidation
public void setErrorMessage(String errorMessage)
GeneratedVaadinTextField
Description copied from corresponding location in WebComponent:
Error to show when the input value is invalid.
setErrorMessage
in interface HasValidation
setErrorMessage
in class GeneratedVaadinTextField<BigDecimalField,BigDecimal>
errorMessage
- the String value to setpublic boolean isInvalid()
HasValidation
true
if component input is invalid, false
otherwise.isInvalid
in interface HasValidation
public void setInvalid(boolean invalid)
GeneratedVaadinTextField
Description copied from corresponding location in WebComponent:
This property is set to true when the control value is invalid.
setInvalid
in interface HasValidation
setInvalid
in class GeneratedVaadinTextField<BigDecimalField,BigDecimal>
invalid
- the boolean value to setpublic void setLabel(String label)
setLabel
in interface HasLabel
setLabel
in class GeneratedVaadinTextField<BigDecimalField,BigDecimal>
label
- value for the label
property in the webcomponentpublic String getLabel()
public void setPlaceholder(String placeholder)
GeneratedVaadinTextField
Description copied from corresponding location in WebComponent:
A hint to the user of what can be entered in the control.
setPlaceholder
in class GeneratedVaadinTextField<BigDecimalField,BigDecimal>
placeholder
- the String value to setpublic String getPlaceholder()
placeholder
property from the webcomponentpublic boolean isAutoselect()
true
if autoselect is active, false
otherwisepublic void setAutoselect(boolean autoselect)
true
to always have the field value automatically
selected when the field gains focus, false
otherwise.setAutoselect
in class GeneratedVaadinTextField<BigDecimalField,BigDecimal>
autoselect
- true
to set auto select on, false
otherwisepublic boolean isClearButtonVisible()
true
if the button is visible, false
otherwisepublic void setClearButtonVisible(boolean clearButtonVisible)
false
to hide the clear button which clears the text
field.setClearButtonVisible
in class GeneratedVaadinTextField<BigDecimalField,BigDecimal>
clearButtonVisible
- true
to set the button visible,
false
otherwisepublic void setAutofocus(boolean autofocus)
GeneratedVaadinTextField
Description copied from corresponding location in WebComponent:
Specify that this control should have input focus when the page loads.
setAutofocus
in class GeneratedVaadinTextField<BigDecimalField,BigDecimal>
autofocus
- the boolean value to setpublic boolean isAutofocus()
autofocus
property from the webcomponentpublic String getTitle()
title
property from the webcomponentpublic void setTitle(String title)
GeneratedVaadinTextField
Description copied from corresponding location in WebComponent:
The text usually displayed in a tooltip popup when the mouse is over the field.
setTitle
in class GeneratedVaadinTextField<BigDecimalField,BigDecimal>
title
- the String value to setpublic BigDecimal getEmptyValue()
HasValue
By default HasValue
is expected to support null
as empty
values. Specific implementations might not support this.
getEmptyValue
in interface HasValue<AbstractField.ComponentValueChangeEvent<BigDecimalField,BigDecimal>,BigDecimal>
getEmptyValue
in class AbstractField<BigDecimalField,BigDecimal>
public void setValue(BigDecimal value)
getValue()
, fires a value change event.
You can adjust how the value is presented in the field with the APIs
provided by the value type BigDecimal
. For example, you can
change the number of decimal places with
BigDecimal.setScale(int)
. This doesn't however restrict the user
from entering values with different number of decimals. Note that
BigDecimals are immutable, so their methods will return new instances
instead of editing the existing ones. Scientific notation (such as 1e9)
is turned into plain number format for the presentation.
setValue
in interface HasValue<AbstractField.ComponentValueChangeEvent<BigDecimalField,BigDecimal>,BigDecimal>
setValue
in class AbstractField<BigDecimalField,BigDecimal>
value
- the new valuepublic BigDecimal getValue()
null
.getValue
in interface HasValue<AbstractField.ComponentValueChangeEvent<BigDecimalField,BigDecimal>,BigDecimal>
getValue
in class AbstractField<BigDecimalField,BigDecimal>
protected void validate()
validate
in class GeneratedVaadinTextField<BigDecimalField,BigDecimal>
public Validator<BigDecimal> getDefaultValidator()
HasValidator
Binder
and
can be seen as a validation failure.getDefaultValidator
in interface HasValidator<BigDecimal>
public Registration addValidationStatusChangeListener(ValidationStatusChangeListener<BigDecimal> listener)
HasValidator
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 by HasValidator.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 including HasValidator.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));
}
}
}
addValidationStatusChangeListener
in interface HasValidator<BigDecimal>
Binder.BindingBuilderImpl.bind(ValueProvider,
Setter)
public void setLocale(Locale locale)
locale
- the locale to set, not null
public Locale getLocale()
protected void onAttach(AttachEvent attachEvent)
Component
The default implementation does nothing.
This method is invoked before the AttachEvent
is fired for the
component.
protected boolean isEnforcedFieldValidationEnabled()
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.
true
if enabled, false
otherwise.Copyright © 2025. All rights reserved.