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

@Tag("vaadin-custom-field") @NpmPackage(value="@vaadin/polymer-legacy-adapter",version="24.3.11") @NpmPackage(value="@vaadin/custom-field",version="24.3.11") @JsModule("@vaadin/polymer-legacy-adapter/style-modules.js") @JsModule("@vaadin/custom-field/src/vaadin-custom-field.js") public abstract class CustomField<T> extends AbstractField<CustomField<T>,T> implements Focusable<CustomField<T>>, HasHelper, InputField<AbstractField.ComponentValueChangeEvent<CustomField<T>,T>,T>, HasTheme, 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:
  • Constructor Details

    • 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:
  • Method Details

    • onAttach

      protected void onAttach(AttachEvent attachEvent)
      Description copied from class: Component
      Called when the component is attached to a UI.

      The default implementation does nothing.

      This method is invoked before the AttachEvent is fired for the component.

      Overrides:
      onAttach in class Component
      Parameters:
      attachEvent - the attach event
    • 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.

      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<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(Component... components)
      Adds the given components as children of this component.
      Parameters:
      components - the components to add
    • remove

      protected void remove(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

      public String getLabel()
      Gets the label for the field.
      Specified by:
      getLabel in interface 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 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