Class CustomField<T>
java.lang.Object
com.vaadin.flow.component.Component
com.vaadin.flow.component.AbstractField<CustomField<T>,T>
com.vaadin.flow.component.customfield.CustomField<T>
- Type Parameters:
T- field value type
- All Implemented Interfaces:
com.vaadin.flow.component.AttachNotifier,com.vaadin.flow.component.BlurNotifier<CustomField<T>>,com.vaadin.flow.component.DetachNotifier,com.vaadin.flow.component.Focusable<CustomField<T>>,com.vaadin.flow.component.FocusNotifier<CustomField<T>>,com.vaadin.flow.component.HasElement,com.vaadin.flow.component.HasEnabled,com.vaadin.flow.component.HasHelper,com.vaadin.flow.component.HasLabel,com.vaadin.flow.component.HasSize,com.vaadin.flow.component.HasStyle,com.vaadin.flow.component.HasTheme,com.vaadin.flow.component.HasValidation,com.vaadin.flow.component.HasValue<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<CustomField<T>,,T>, T> com.vaadin.flow.component.HasValueAndElement<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<CustomField<T>,,T>, T> com.vaadin.flow.component.shared.HasTooltip,com.vaadin.flow.component.shared.HasValidationProperties,com.vaadin.flow.component.shared.InputField<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<CustomField<T>,,T>, T> Serializable
@Tag("vaadin-custom-field")
@NpmPackage(value="@vaadin/custom-field",
version="25.0.0-alpha21")
@JsModule("@vaadin/custom-field/src/vaadin-custom-field.js")
public abstract class CustomField<T>
extends com.vaadin.flow.component.AbstractField<CustomField<T>,T>
implements com.vaadin.flow.component.Focusable<CustomField<T>>, com.vaadin.flow.component.shared.InputField<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<CustomField<T>,T>,T>, com.vaadin.flow.component.HasTheme, com.vaadin.flow.component.shared.HasValidationProperties
A
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).
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class com.vaadin.flow.component.AbstractField
com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<C extends com.vaadin.flow.component.Component,V> Nested classes/interfaces inherited from interface com.vaadin.flow.component.BlurNotifier
com.vaadin.flow.component.BlurNotifier.BlurEvent<C extends com.vaadin.flow.component.Component>Nested classes/interfaces inherited from interface com.vaadin.flow.component.FocusNotifier
com.vaadin.flow.component.FocusNotifier.FocusEvent<C extends com.vaadin.flow.component.Component>Nested classes/interfaces inherited from interface com.vaadin.flow.component.HasValue
com.vaadin.flow.component.HasValue.ValueChangeEvent<V>, com.vaadin.flow.component.HasValue.ValueChangeListener<E extends com.vaadin.flow.component.HasValue.ValueChangeEvent<?>> -
Constructor Summary
ConstructorsConstructorDescriptionDefault constructor.CustomField(T defaultValue) Constructs a new custom field.CustomField(T defaultValue, boolean manualValueUpdate) Constructs a new custom field. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidadd(com.vaadin.flow.component.Component... components) Adds the given components as children of this component.voidaddThemeVariants(CustomFieldVariant... variants) Adds theme variants to the component.protected abstract TThis method should return the value of the field, based on value of the internal fields.getLabel()Gets the label for the field.protected voidremove(com.vaadin.flow.component.Component... components) Removes the given child components from this component.voidremoveThemeVariants(CustomFieldVariant... variants) Removes theme variants from the component.voidSets the label for the field.protected abstract voidsetPresentationValue(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 voidRegenerates the value by callinggenerateModelValue()and updates the model.Methods inherited from class com.vaadin.flow.component.AbstractField
addValueChangeListener, getEmptyValue, getValue, isEmpty, setModelValue, setValue, valueEqualsMethods inherited from class com.vaadin.flow.component.Component
addListener, findAncestor, fireEvent, from, get, getChildren, getElement, getEventBus, getId, getListeners, getLocale, getParent, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getUI, hasListener, isAttached, isTemplateMapped, isVisible, onAttach, onDetach, onEnabledStateChanged, removeFromParent, scrollIntoView, scrollIntoView, set, setElement, setId, setVisibleMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.vaadin.flow.component.AttachNotifier
addAttachListenerMethods inherited from interface com.vaadin.flow.component.BlurNotifier
addBlurListenerMethods inherited from interface com.vaadin.flow.component.DetachNotifier
addDetachListenerMethods inherited from interface com.vaadin.flow.component.Focusable
addFocusShortcut, blur, focus, getTabIndex, setTabIndexMethods inherited from interface com.vaadin.flow.component.FocusNotifier
addFocusListenerMethods inherited from interface com.vaadin.flow.component.HasElement
getElementMethods inherited from interface com.vaadin.flow.component.HasEnabled
isEnabled, setEnabledMethods inherited from interface com.vaadin.flow.component.HasHelper
getHelperComponent, getHelperText, setHelperComponent, setHelperTextMethods 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, setWidthFullMethods inherited from interface com.vaadin.flow.component.HasStyle
addClassName, addClassNames, getClassName, getClassNames, getStyle, hasClassName, removeClassName, removeClassNames, setClassName, setClassNameMethods inherited from interface com.vaadin.flow.component.HasTheme
addThemeName, addThemeNames, getThemeName, getThemeNames, hasThemeName, removeThemeName, removeThemeNames, setThemeName, setThemeNameMethods inherited from interface com.vaadin.flow.component.shared.HasTooltip
getTooltip, setTooltipMarkdown, setTooltipTextMethods inherited from interface com.vaadin.flow.component.HasValidation
setManualValidationMethods inherited from interface com.vaadin.flow.component.shared.HasValidationProperties
getErrorMessage, isInvalid, setErrorMessage, setInvalidMethods inherited from interface com.vaadin.flow.component.HasValue
addValueChangeListener, clear, getEmptyValue, getOptionalValue, getValue, isEmpty, setValueMethods inherited from interface com.vaadin.flow.component.HasValueAndElement
isReadOnly, isRequiredIndicatorVisible, setReadOnly, setRequiredIndicatorVisible
-
Constructor Details
-
CustomField
public CustomField()Default constructor. -
CustomField
Constructs a new custom field.- Parameters:
defaultValue- The initial value for the field. Will also be used byAbstractField.getEmptyValue().- See Also:
-
CustomField
Constructs a new custom field.- Parameters:
defaultValue- The initial value for the field. Will also be used byAbstractField.getEmptyValue().manualValueUpdate- whentruethe component does not automatically update its value when one of the contained fields changes. This allows controlling manually when the value is updated, which can be done by callingupdateValue().falseby default.- See Also:
-
-
Method Details
-
generateModelValue
This method should return the value of the field, based on value of the internal fields.- Returns:
- new value of the field.
-
setPresentationValue
This method should be implemented to set the value of the fields contained in this custom field according to the value of the parameter. It can also be use to show the value to the user in some way, like placing it in an element contained on the field.- Specified by:
setPresentationValuein classcom.vaadin.flow.component.AbstractField<CustomField<T>,T> - Parameters:
newPresentationValue- The new presentation value.
-
updateValue
protected void updateValue()Regenerates the value by callinggenerateModelValue()and updates the model. If the value is different than the current one, aHasValue.ValueChangeEventwill be generated withHasValue.ValueChangeEvent.isFromClient()set totrueThis 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. -
add
protected void add(com.vaadin.flow.component.Component... components) Adds the given components as children of this component.- Parameters:
components- the components to add
-
remove
protected void remove(com.vaadin.flow.component.Component... components) Removes the given child components from this component.- Parameters:
components- the components to remove- Throws:
IllegalArgumentException- if any of the components is not a child of this component
-
getLabel
Gets the label for the field.- Specified by:
getLabelin interfacecom.vaadin.flow.component.HasLabel- Returns:
- the
labelproperty from the webcomponent
-
setLabel
Sets the label for the field.- Specified by:
setLabelin interfacecom.vaadin.flow.component.HasLabel- Parameters:
label- value for thelabelproperty in the webcomponent
-
addThemeVariants
Adds theme variants to the component.- Parameters:
variants- theme variants to add
-
removeThemeVariants
Removes theme variants from the component.- Parameters:
variants- theme variants to remove
-