Class CustomField<T>

java.lang.Object
com.vaadin.flow.component.Component
com.vaadin.flow.component.Composite<com.vaadin.flow.component.Component>
com.vaadin.flow.component.AbstractCompositeField<com.vaadin.flow.component.Component,CustomField<T>,T>
com.vaadin.featurepack.ui.CustomField<T>
Type Parameters:
T - field value type
All Implemented Interfaces:
Buffered, BufferedValidatable, Property<T>, Property.Editor, Property.ReadOnlyStatusChangeListener, Property.ReadOnlyStatusChangeNotifier, Property.ValueChangeListener, Property.ValueChangeNotifier, Property.Viewer, Field<T>, Validatable, ClientConnector, FAbstractClientConnector, FSizeable, HasSizeable, FAbstractComponent, Focusable, HasComponents, HasFInternalValue<T>, com.vaadin.flow.component.AttachNotifier, com.vaadin.flow.component.BlurNotifier<com.vaadin.flow.component.html.Div>, com.vaadin.flow.component.DetachNotifier, com.vaadin.flow.component.Focusable<com.vaadin.flow.component.html.Div>, com.vaadin.flow.component.FocusNotifier<com.vaadin.flow.component.html.Div>, com.vaadin.flow.component.HasElement, com.vaadin.flow.component.HasEnabled, com.vaadin.flow.component.HasSize, com.vaadin.flow.component.HasStyle, 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>, Serializable, Iterable<com.vaadin.flow.component.Component>
Direct Known Subclasses:
FTokenField

public abstract class CustomField<T> extends com.vaadin.flow.component.AbstractCompositeField<com.vaadin.flow.component.Component,CustomField<T>,T> implements FAbstractComponent, HasFInternalValue<T>, HasComponents, Focusable, com.vaadin.flow.component.Focusable<com.vaadin.flow.component.html.Div>, com.vaadin.flow.component.HasValueAndElement<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<CustomField<T>,T>,T>, HasSizeable
A Field 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 Field.getType() and initContent(). Most custom fields can simply compose a user interface that calls the methods setInternalValue(Object) and getInternalValue() when necessary. It is also possible to override validate(), setInternalValue(Object), Field.commit(), Field.setPropertyDataSource(com.vaadin.featurepack.data.Property), AbstractCompositeField.isEmpty() and other logic of the field. Methods overriding setInternalValue(Object) should also call the corresponding superclass method.
See Also:
  • Constructor Details

    • CustomField

      public CustomField()
      Constructs a new custom field.

      The component is implemented by wrapping the methods of the composition root component given as parameter. The composition root must be set before the component can be used.

  • Method Details

    • onAttach

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

      protected void onDetach(com.vaadin.flow.component.DetachEvent detachEvent)
      Overrides:
      onDetach in class com.vaadin.flow.component.Component
    • setLabelComponent

      public void setLabelComponent(com.vaadin.flow.component.Component labelComponent)
      Description copied from interface: FAbstractComponent
      Sets the component's label component. Flow components that support caption component usually overrides this.
      Specified by:
      setLabelComponent in interface FAbstractComponent
      Parameters:
      labelComponent - the new label component for the component.
    • attach

      public void attach()
      Constructs the content and notifies it that the CustomField is attached to a window.
      Specified by:
      attach in interface ClientConnector
      Specified by:
      attach in interface FAbstractClientConnector
    • getContent

      public com.vaadin.flow.component.Component getContent()
      Returns the content (UI) of the custom component.
      Overrides:
      getContent in class com.vaadin.flow.component.Composite<com.vaadin.flow.component.Component>
      Returns:
      Component
    • getElement

      public com.vaadin.flow.dom.Element getElement()
      Specified by:
      getElement in interface com.vaadin.flow.component.HasElement
      Overrides:
      getElement in class com.vaadin.flow.component.Composite<com.vaadin.flow.component.Component>
    • getChildren

      public Stream<com.vaadin.flow.component.Component> getChildren()
      Overrides:
      getChildren in class com.vaadin.flow.component.Composite<com.vaadin.flow.component.Component>
    • initContent

      protected abstract com.vaadin.flow.component.Component initContent()
      Create the content component or layout for the field. Subclasses of CustomField should implement this method.

      Note that this method is called when the CustomField is attached to a layout or when getContent() is called explicitly for the first time. It is only called once for a CustomField.

      Overrides:
      initContent in class com.vaadin.flow.component.Composite<com.vaadin.flow.component.Component>
      Returns:
      Component representing the UI of the CustomField
    • setHeight

      public void setHeight(float height, com.vaadin.flow.component.Unit unit)
      Description copied from interface: FSizeable
      Sets the height of the object. Negative number implies unspecified size (terminal is free to set the size).
      Specified by:
      setHeight in interface FSizeable
      Specified by:
      setHeight in interface com.vaadin.flow.component.HasSize
      Specified by:
      setHeight in interface HasSizeable
      Parameters:
      height - the height of the object.
      unit - the unit used for the width.
    • setWidth

      public void setWidth(float width, com.vaadin.flow.component.Unit unit)
      Description copied from interface: FSizeable
      Sets the width of the object. Negative number implies unspecified size (terminal is free to set the size).
      Specified by:
      setWidth in interface FSizeable
      Specified by:
      setWidth in interface com.vaadin.flow.component.HasSize
      Specified by:
      setWidth in interface HasSizeable
      Parameters:
      width - the width of the object.
      unit - the unit used for the width.
    • setSizeFull

      public void setSizeFull()
      Description copied from interface: FSizeable
      Sets the size to 100% x 100%.
      Specified by:
      setSizeFull in interface FSizeable
      Specified by:
      setSizeFull in interface com.vaadin.flow.component.HasSize
      Specified by:
      setSizeFull in interface HasSizeable
    • setSizeUndefined

      public void setSizeUndefined()
      Description copied from interface: FSizeable
      Clears any size settings.
      Specified by:
      setSizeUndefined in interface FSizeable
      Specified by:
      setSizeUndefined in interface com.vaadin.flow.component.HasSize
      Specified by:
      setSizeUndefined in interface HasSizeable
    • setWidthUndefined

      public void setWidthUndefined()
      Description copied from interface: FSizeable
      Clears any defined width.
      Specified by:
      setWidthUndefined in interface FSizeable
      Specified by:
      setWidthUndefined in interface HasSizeable
    • setHeightUndefined

      public void setHeightUndefined()
      Description copied from interface: FSizeable
      Clears any defined height.
      Specified by:
      setHeightUndefined in interface FSizeable
      Specified by:
      setHeightUndefined in interface HasSizeable
    • iterator

      public Iterator<com.vaadin.flow.component.Component> iterator()
      Description copied from interface: HasComponents
      Gets an iterator to the collection of contained components. Using this iterator it is possible to step through all components contained in this container.

      The iterator is typically unmodifiable, and calls to Iterator.remove() throw an exception.

      Specified by:
      iterator in interface HasComponents
      Specified by:
      iterator in interface Iterable<T>
      Returns:
      the component iterator.
    • setFocusDelegate

      public void setFocusDelegate(Focusable focusDelegate)
      Sets the component to which all methods from the Focusable interface should be delegated.

      Set this to a wrapped field to include that field in the tabbing order, to make it receive focus when focus() is called and to make it be correctly focused when used as a Grid editor component.

      By default, Focusable events are handled by the super class and ultimately ignored.

      Parameters:
      focusDelegate - the focusable component to which focus events are redirected
    • focus

      public void focus()
      Description copied from interface: Focusable
      Sets the focus to this component.
      Specified by:
      focus in interface Focusable
      Specified by:
      focus in interface com.vaadin.flow.component.Focusable<T>
    • getTabIndex

      public int getTabIndex()
      Description copied from interface: Focusable
      Gets the tabulator index of the Focusable component.
      Specified by:
      getTabIndex in interface Focusable
      Specified by:
      getTabIndex in interface com.vaadin.flow.component.Focusable<T>
      Returns:
      tab index set for the Focusable component
      See Also:
    • setTabIndex

      public void setTabIndex(int tabIndex)
      Description copied from interface: Focusable
      Sets the tabulator index of the Focusable component. The tab index property is used to specify the order in which the fields are focused when the user presses the Tab key. Components with a defined tab index are focused sequentially first, and then the components with no tab index.

      After all focusable user interface components are done, the browser can begin again from the component with the smallest tab index, or it can take the focus out of the page, for example, to the location bar.

      If the tab index is not set (is set to zero), the default tab order is used. The order is somewhat browser-dependent, but generally follows the HTML structure of the page.

      A negative value means that the component is completely removed from the tabulation order and can not be reached by pressing the Tab key at all.

      Specified by:
      setTabIndex in interface Focusable
      Specified by:
      setTabIndex in interface com.vaadin.flow.component.Focusable<T>
      Parameters:
      tabIndex - the tab order of this component. Indexes usually start from 1. Zero means that default tab order should be used. A negative value means that the field should not be included in the tabbing sequence.
      See Also:
    • validate

      public void validate() throws Validator.InvalidValueException
      Description copied from interface: Validatable

      Checks the validity of the validatable. If the validatable is valid this method should do nothing, and if it's not valid, it should throw Validator.InvalidValueException

      Specified by:
      validate in interface Validatable
      Throws:
      Validator.InvalidValueException - if the value is not valid
    • setPresentationValue

      protected void setPresentationValue(T value)
      Specified by:
      setPresentationValue in class com.vaadin.flow.component.AbstractCompositeField<com.vaadin.flow.component.Component,CustomField<T>,T>
    • getInternalValue

      protected T getInternalValue()
    • setInternalValue

      protected void setInternalValue(T newValue)
    • getFInternalValue

      public T getFInternalValue()
      Specified by:
      getFInternalValue in interface HasFInternalValue<T>
    • setFInternalValue

      public void setFInternalValue(T newValue)
      Specified by:
      setFInternalValue in interface HasFInternalValue<T>
    • fireEvent

      protected void fireEvent(com.vaadin.flow.component.ComponentEvent<?> componentEvent)
      Overrides:
      fireEvent in class com.vaadin.flow.component.Component