Class AbstractSinglePropertyField<C extends AbstractField<C,​T>,​T>

    • 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 use
        defaultValue - the default value to use if the property isn't defined
        acceptNullValues - if true, an exception will be thrown if the model value is set to null; if false the property will be removed when the model value is set to null
      • 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 type
        Parameters:
        propertyName - the name of the element property to use
        defaultValue - the default value to use if the property isn't defined
        elementPropertyType - the type of the element property
        presentationToModel - a function that converts a property value to a model value
        modelToPresentation - 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 type
        Parameters:
        propertyName - the name of the element property to use
        defaultValue - the default value to use if the property isn't defined
        elementPropertyType - the type of the element property
        presentationToModel - a function that accepts this component and a property value and returns a model value
        modelToPresentation - 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 is value, then the event default name is value-changed.
        Parameters:
        synchronizedEvent - the property name to synchronize, or null to disable property synchronization
        See 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 return true.
        Returns:
        true if the element property value can be converted to the model type; otherwise false
      • 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 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.

        Specified by:
        setPresentationValue in class AbstractField<C extends AbstractField<C,​T>,​T>
        Parameters:
        newPresentationValue - the new value to show