T
- field value type@Tag(value="vaadin-custom-field") @NpmPackage(value="@vaadin/vaadin-custom-field", version="1.4.0") @JsModule(value="@vaadin/vaadin-custom-field/src/vaadin-custom-field.js") public abstract class CustomField<T> extends AbstractField<CustomField<T>,T> implements HasSize, HasValidation, Focusable<CustomField>, HasHelper, HasLabel
HasValue
whose UI content can be constructed by the user, enabling
the creation of e.g. form fields by composing Vaadin components.
Customization of both the visual presentation and the logic of the field is
possible.
Subclasses must implement generateModelValue()
and
AbstractFieldsetPresentationValue(Object)
.
AbstractField.ComponentValueChangeEvent<C extends Component,V>
BlurNotifier.BlurEvent<C extends Component>
FocusNotifier.FocusEvent<C extends Component>
HasValue.ValueChangeEvent<V>, HasValue.ValueChangeListener<E extends HasValue.ValueChangeEvent<?>>
Constructor and Description |
---|
CustomField()
Default constructor.
|
CustomField(T defaultValue)
Constructs a new custom field.
|
Modifier and Type | Method and Description |
---|---|
protected void |
add(Component... components)
Adds the given components as children of this component.
|
protected abstract T |
generateModelValue()
This method should return the value of the field, based on value of the
internal fields.
|
String |
getErrorMessage()
Gets current error message from the component.
|
String |
getLabel()
Gets the label for the field.
|
boolean |
isInvalid()
This property is set to true when the control value is invalid.
|
protected void |
remove(Component... components)
Removes the given child components from this component.
|
void |
setErrorMessage(String errorMessage)
Sets an error message to the component.
|
void |
setInvalid(boolean invalid)
This property is set to true when the control value is invalid.
|
void |
setLabel(String label)
Sets the label for the field.
|
protected abstract void |
setPresentationValue(T newPresentationValue)
This method should be implemented to set the value of the fields
contained in this custom field according to the value of the parameter.
|
protected void |
updateValue()
Regenerates the value by calling
generateModelValue() and
updates the model. |
addValueChangeListener, getEmptyValue, getValue, isEmpty, setModelValue, setValue, valueEquals
addListener, fireEvent, from, get, getChildren, getElement, getEventBus, getId, getLocale, getParent, getTranslation, getTranslation, getTranslation, getTranslation, getUI, hasListener, isAttached, isTemplateMapped, isVisible, onAttach, 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
addFocusShortcut, blur, focus, getTabIndex, setTabIndex
addBlurListener
addFocusListener
isEnabled, setEnabled
getElement
getHelperComponent, getHelperText, setHelperComponent, setHelperText
isReadOnly, isRequiredIndicatorVisible, setReadOnly, setRequiredIndicatorVisible
clear, getOptionalValue
addAttachListener
addDetachListener
public CustomField()
public CustomField(T defaultValue)
defaultValue
- The initial value for the field. Will also be used by
AbstractField.getEmptyValue()
.AbstractField.AbstractField(Object)
protected abstract T generateModelValue()
protected abstract void setPresentationValue(T newPresentationValue)
Updates the presentation of this field to display the provided value. Subclasses should override this method to show the value to the user. This is typically done by setting an element property or by applying changes to child components.
If AbstractField.setModelValue(Object, boolean)
is called from within this
method, the value of the last invocation will be used as the model value
instead of the value passed to this method. In this case
AbstractField.setPresentationValue(Object)
will not be called again. Changing
the provided value might be useful if the provided value is sanitized.
See AbstractField
for an overall description on the difference
between model values and presentation values.
setPresentationValue
in class AbstractField<CustomField<T>,T>
newPresentationValue
- The new presentation value.protected void updateValue()
generateModelValue()
and
updates the model. If the value is different than the current one, a
ValueChangeEvent
will be generated with
ValueChangeEvent#isFromClient()
set to true
This method is called when the webcomponent generates a changed event, typically in response to a change made by the user in one of the contained fields.
Custom implementations of this method must call
AbstractField.setModelValue(Object, boolean)
with the updated model value.
Subclasses can call this method when the model value needs to be
regenerated and updated.
protected void add(Component... components)
components
- the components to addprotected void remove(Component... components)
components
- the components to removeIllegalArgumentException
- if any of the components is not a child of this component@Synchronize(property="invalid", value="invalid-changed") public boolean isInvalid()
This property is set to true when the control value is invalid.
This property is synchronized automatically from client side when a 'invalid-changed' event happens.
isInvalid
in interface HasValidation
invalid
property from the webcomponentpublic void setInvalid(boolean invalid)
This property is set to true when the control value is invalid.
setInvalid
in interface HasValidation
invalid
- the boolean value to setpublic void setErrorMessage(String errorMessage)
HasValidation
The Web Component is responsible for deciding when to show the error message to the user, and this is usually triggered by triggering the invalid state for the Web Component. Which means that there is no need to clean up the message when component becomes valid (otherwise it may lead to undesired visual effects).
setErrorMessage
in interface HasValidation
errorMessage
- a new error messagepublic String getErrorMessage()
HasValidation
getErrorMessage
in interface HasValidation
public String getLabel()
Copyright © 2025. All rights reserved.