Class CustomField<T>
- Type Parameters:
T
- field value type
- All Implemented Interfaces:
AttachNotifier
,BlurNotifier<CustomField<T>>
,DetachNotifier
,Focusable<CustomField<T>>
,FocusNotifier<CustomField<T>>
,HasElement
,HasEnabled
,HasHelper
,HasLabel
,HasSize
,HasStyle
,HasTheme
,HasValidation
,HasValue<AbstractField.ComponentValueChangeEvent<CustomField<T>,
,T>, T> HasValueAndElement<AbstractField.ComponentValueChangeEvent<CustomField<T>,
,T>, T> HasTooltip
,HasValidationProperties
,InputField<AbstractField.ComponentValueChangeEvent<CustomField<T>,
,T>, T> Serializable
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
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<?>>
-
Constructor Summary
ConstructorsConstructorDescriptionDefault constructor.CustomField
(T defaultValue) Constructs a new custom field. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
Adds the given components as children of this component.void
addThemeVariants
(CustomFieldVariant... variants) Adds theme variants to the component.protected abstract T
This method should return the value of the field, based on value of the internal fields.getLabel()
Gets the label for the field.protected void
onAttach
(AttachEvent attachEvent) Called when the component is attached to a UI.protected void
Removes the given child components from this component.void
removeThemeVariants
(CustomFieldVariant... variants) Removes theme variants from the component.void
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
Regenerates the value by callinggenerateModelValue()
and updates the model.Methods inherited from class com.vaadin.flow.component.AbstractField
addValueChangeListener, getEmptyValue, getValue, isEmpty, setModelValue, setValue, valueEquals
Methods 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, onDetach, onEnabledStateChanged, removeFromParent, scrollIntoView, 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.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.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.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.shared.HasTooltip
getTooltip, setTooltipText
Methods inherited from interface com.vaadin.flow.component.HasValidation
setManualValidation
Methods inherited from interface com.vaadin.flow.component.shared.HasValidationProperties
getErrorMessage, isInvalid, setErrorMessage, setInvalid
Methods inherited from interface com.vaadin.flow.component.HasValue
addValueChangeListener, clear, getEmptyValue, getOptionalValue, getValue, isEmpty, setValue
Methods 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:
-
-
Method Details
-
onAttach
Description copied from class:Component
Called when the component is attached to a UI.This method is invoked before the
Make sure to callAttachEvent
is fired for the component.super.onAttach
when overriding this method. -
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.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 caseAbstractField.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.- Specified by:
setPresentationValue
in classAbstractField<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.ValueChangeEvent
will be generated withHasValue.ValueChangeEvent.isFromClient()
set totrue
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. -
add
Adds the given components as children of this component.- Parameters:
components
- the components to add
-
remove
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. -
setLabel
Sets the label for the field. -
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
-