Class CustomField<T>

  • Type Parameters:
    T - field value type
    All Implemented Interfaces:
    com.vaadin.flow.component.AttachNotifier, com.vaadin.flow.component.BlurNotifier<CustomField>, com.vaadin.flow.component.DetachNotifier, com.vaadin.flow.component.Focusable<CustomField>, com.vaadin.flow.component.FocusNotifier<CustomField>, 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>, HasTooltip, Serializable

    @Tag("vaadin-custom-field")
    @NpmPackage(value="@vaadin/polymer-legacy-adapter",version="23.6.1") @NpmPackage(value="@vaadin/custom-field",version="23.6.1") @NpmPackage(value="@vaadin/vaadin-custom-field",version="23.6.1")
    @JsModule("@vaadin/polymer-legacy-adapter/style-modules.js") @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.HasSize, com.vaadin.flow.component.HasValidation, com.vaadin.flow.component.Focusable<CustomField>, com.vaadin.flow.component.HasHelper, com.vaadin.flow.component.HasLabel, com.vaadin.flow.component.HasTheme, com.vaadin.flow.component.HasStyle, HasTooltip
    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:
    Serialized Form
    • 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 extends Object>
      • 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 extends Object>, com.vaadin.flow.component.HasValue.ValueChangeListener<E extends com.vaadin.flow.component.HasValue.ValueChangeEvent<?>>
    • Constructor Summary

      Constructors 
      Constructor Description
      CustomField()
      Default constructor.
      CustomField​(T defaultValue)
      Constructs a new custom field.
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      protected void add​(com.vaadin.flow.component.Component... components)
      Adds the given components as children of this component.
      void addThemeVariants​(CustomFieldVariant... variants)
      Adds theme variants to the component.
      protected abstract T generateModelValue()
      This method should return the value of the field, based on value of the internal fields.
      String getErrorMessage()  
      String getLabel()
      Gets the label for the field.
      boolean isInvalid()
      This property is set to true when the control value is invalid.
      protected void onAttach​(com.vaadin.flow.component.AttachEvent attachEvent)  
      protected void remove​(com.vaadin.flow.component.Component... components)
      Removes the given child components from this component.
      void removeThemeVariants​(CustomFieldVariant... variants)
      Removes theme variants from the component.
      void setErrorMessage​(String errorMessage)  
      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.
      • 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, scrollIntoView, set, setElement, setId, setVisible
      • 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.HasValue

        clear, getOptionalValue
      • Methods inherited from interface com.vaadin.flow.component.HasValueAndElement

        isReadOnly, isRequiredIndicatorVisible, setReadOnly, setRequiredIndicatorVisible
    • Constructor Detail

      • CustomField

        public CustomField()
        Default constructor.
      • CustomField

        public CustomField​(T defaultValue)
        Constructs a new custom field.
        Parameters:
        defaultValue - The initial value for the field. Will also be used by AbstractField.getEmptyValue().
        See Also:
        AbstractField(Object)
    • Method Detail

      • onAttach

        protected void onAttach​(com.vaadin.flow.component.AttachEvent attachEvent)
        Overrides:
        onAttach in class com.vaadin.flow.component.Component
      • generateModelValue

        protected abstract T generateModelValue()
        This method should return the value of the field, based on value of the internal fields.
        Returns:
        new value of the field.
      • setPresentationValue

        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. 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:
        setPresentationValue in class com.vaadin.flow.component.AbstractField<CustomField<T>,​T>
        Parameters:
        newPresentationValue - The new presentation value.
      • updateValue

        protected void updateValue()
        Regenerates the value by calling generateModelValue() and updates the model. If the value is different than the current one, a HasValue.ValueChangeEvent will be generated with HasValue.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.

      • 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
      • isInvalid

        public boolean isInvalid()

        This property is set to true when the control value is invalid.

        Specified by:
        isInvalid in interface com.vaadin.flow.component.HasValidation
        Returns:
        the invalid property from the webcomponent
      • setInvalid

        public void setInvalid​(boolean invalid)

        This property is set to true when the control value is invalid.

        Specified by:
        setInvalid in interface com.vaadin.flow.component.HasValidation
        Parameters:
        invalid - the boolean value to set
      • setErrorMessage

        public void setErrorMessage​(String errorMessage)
        Specified by:
        setErrorMessage in interface com.vaadin.flow.component.HasValidation
      • getErrorMessage

        public String getErrorMessage()
        Specified by:
        getErrorMessage in interface com.vaadin.flow.component.HasValidation
      • getLabel

        public String getLabel()
        Gets the label for the field.
        Specified by:
        getLabel in interface com.vaadin.flow.component.HasLabel
        Returns:
        the label property from the webcomponent
      • setLabel

        public void setLabel​(String label)
        Sets the label for the field.
        Specified by:
        setLabel in interface com.vaadin.flow.component.HasLabel
        Parameters:
        label - value for the label property in the webcomponent
      • addThemeVariants

        public void addThemeVariants​(CustomFieldVariant... variants)
        Adds theme variants to the component.
        Parameters:
        variants - theme variants to add
      • removeThemeVariants

        public void removeThemeVariants​(CustomFieldVariant... variants)
        Removes theme variants from the component.
        Parameters:
        variants - theme variants to remove