com.vaadin.flow.component.
Class AbstractSinglePropertyField<C extends AbstractField<C,T>,T>
- java.lang.Object
-
- com.vaadin.flow.component.Component
-
- com.vaadin.flow.component.AbstractField<C,T>
-
- com.vaadin.flow.component.AbstractSinglePropertyField<C,T>
-
Type Parameters:
C
- the source type for value change eventsT
- the value typeAll Implemented Interfaces:
AttachNotifier, DetachNotifier, HasElement, HasEnabled, HasValue<AbstractField.ComponentValueChangeEvent<C,T>,T>, HasValueAndElement<AbstractField.ComponentValueChangeEvent<C,T>,T>, Serializable
Direct Known Subclasses:
DateTimePicker, GeneratedVaadinCheckbox, GeneratedVaadinCheckboxGroup, GeneratedVaadinComboBox, GeneratedVaadinDatePicker, GeneratedVaadinRadioGroup, GeneratedVaadinRichTextEditor, GeneratedVaadinSelect, GeneratedVaadinTextArea, GeneratedVaadinTextField, GeneratedVaadinTimePicker, Input, ListBoxBase
public class AbstractSinglePropertyField<C extends AbstractField<C,T>,T> extends AbstractField<C,T>
Abstract field that is based on a single element property.
Since:
1.0
Author:
Vaadin Ltd
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.HasValue
HasValue.ValueChangeEvent<V>, HasValue.ValueChangeListener<E extends HasValue.ValueChangeEvent<?>>
-
-
Constructor Summary
Constructors Constructor and Description AbstractSinglePropertyField(String propertyName, T defaultValue, boolean acceptNullValues)
Creates a new field that uses a property value without any conversion.
AbstractSinglePropertyField(String propertyName, T defaultValue, Class<P> elementPropertyType, SerializableBiFunction<C,P,T> presentationToModel, SerializableBiFunction<C,T,P> modelToPresentation)
Creates a new field that uses a property value with the given contextual converters for producing a model value.
AbstractSinglePropertyField(String propertyName, T defaultValue, Class<P> elementPropertyType, SerializableFunction<P,T> presentationToModel, SerializableFunction<T,P> modelToPresentation)
Creates a new field that uses a property value with the given stateless converters for producing a model value.
-
Method Summary
All Methods Modifier and Type Method and Description protected DomListenerRegistration
getSynchronizationRegistration()
Returns the registration of the DOM event listener that synchronizes the property value.
protected boolean
hasValidValue()
Checks whether the element property has a value that can be converted to the model type.
protected void
setPresentationValue(T newPresentationValue)
Updates the presentation of this field to display the provided value.
protected void
setSynchronizedEvent(String synchronizedEvent)
Sets the name of the DOM event for which property values are synchronized from the client to the server.
-
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, 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
-
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.HasValueAndElement
isReadOnly, isRequiredIndicatorVisible, setReadOnly, setRequiredIndicatorVisible
-
Methods inherited from interface com.vaadin.flow.component.HasValue
clear, getOptionalValue
-
Methods inherited from interface com.vaadin.flow.component.HasEnabled
isEnabled, setEnabled
-
Methods inherited from interface com.vaadin.flow.component.HasElement
getElement
-
Methods inherited from interface com.vaadin.flow.component.AttachNotifier
addAttachListener
-
Methods inherited from interface com.vaadin.flow.component.DetachNotifier
addDetachListener
-
-
-
-
Constructor Detail
-
AbstractSinglePropertyField
public AbstractSinglePropertyField(String propertyName, T defaultValue, boolean acceptNullValues)
Creates a new field that uses a property value without any conversion.
The value type of the class must be one of the types that can be written as an element property value: String, Integer, Double or Boolean.
Parameters:
propertyName
- the name of the element property to usedefaultValue
- the default value to use if the property isn't definedacceptNullValues
- iftrue
, an exception will be thrown if the model value is set tonull
; iffalse
the property will be removed when the model value is set tonull
-
AbstractSinglePropertyField
public AbstractSinglePropertyField(String propertyName, T defaultValue, Class<P> elementPropertyType, SerializableFunction<P,T> presentationToModel, SerializableFunction<T,P> modelToPresentation)
Creates a new field that uses a property value with the given stateless converters for producing a model value.
The property type must be one of the types that can be written as an element property value: String, Integer, Double or Boolean.
Type Parameters:
P
- the property typeParameters:
propertyName
- the name of the element property to usedefaultValue
- the default value to use if the property isn't definedelementPropertyType
- the type of the element propertypresentationToModel
- a function that converts a property value to a model valuemodelToPresentation
- a function that converts a model value to a property value
-
AbstractSinglePropertyField
public AbstractSinglePropertyField(String propertyName, T defaultValue, Class<P> elementPropertyType, SerializableBiFunction<C,P,T> presentationToModel, SerializableBiFunction<C,T,P> modelToPresentation)
Creates a new field that uses a property value with the given contextual converters for producing a model value.
The property type must be one of the types that can be written as an element property value: String, Integer, Double or Boolean.
Type Parameters:
P
- the property typeParameters:
propertyName
- the name of the element property to usedefaultValue
- the default value to use if the property isn't definedelementPropertyType
- the type of the element propertypresentationToModel
- a function that accepts this component and a property value and returns a model valuemodelToPresentation
- a function that accepts this component and a model value and returns a property value
-
-
Method Detail
-
setSynchronizedEvent
protected void setSynchronizedEvent(String synchronizedEvent)
Sets the name of the DOM event for which property values are synchronized from the client to the server. By default, the event name is the property name with
-changed
appended. This means that if the property name isvalue
, then the event default name isvalue-changed
.Parameters:
synchronizedEvent
- the property name to synchronize, ornull
to disable property synchronizationSee Also:
Element.addPropertyChangeListener(String, String, PropertyChangeListener)
,getSynchronizationRegistration()
-
getSynchronizationRegistration
protected DomListenerRegistration getSynchronizationRegistration()
Returns the registration of the DOM event listener that synchronizes the property value. The registration is created by
setSynchronizedEvent(String)
.Returns:
the registration of the DOM event listener that synchronizes the property value, or
null
if property synchronization is disabled
-
hasValidValue
protected boolean hasValidValue()
Checks whether the element property has a value that can be converted to the model type. Property changes from the element will be ignored if this method returns
false
. The default implementation always returntrue
.Returns:
true
if the element property value can be converted to the model type; otherwisefalse
-
setPresentationValue
protected void setPresentationValue(T newPresentationValue)
Description copied from class:
AbstractField
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<C extends AbstractField<C,T>,T>
Parameters:
newPresentationValue
- the new value to show
-
-