Class 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
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:
-
Nested Class Summary
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.featurepack.data.Buffered
Buffered.SourceExceptionNested classes/interfaces inherited from interface com.vaadin.featurepack.server.ClientConnector
ClientConnector.AttachEvent, ClientConnector.AttachListener, ClientConnector.DetachEvent, ClientConnector.DetachListenerNested classes/interfaces inherited from interface com.vaadin.featurepack.server.FAbstractClientConnector
FAbstractClientConnector.LegacyMethodEventNested classes/interfaces inherited from interface com.vaadin.featurepack.ui.FAbstractComponent
FAbstractComponent.DataKeyNested classes/interfaces inherited from interface com.vaadin.featurepack.data.ui.Field
Field.ValueChangeEventNested classes/interfaces inherited from interface com.vaadin.flow.component.Focusable
com.vaadin.flow.component.Focusable.FocusJsNested 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.featurepack.ui.HasComponents
HasComponents.ComponentAttachDetachNotifier, HasComponents.ComponentAttachEvent, HasComponents.ComponentAttachListener, HasComponents.ComponentDetachEvent, HasComponents.ComponentDetachListenerNested classes/interfaces inherited from interface com.vaadin.flow.component.HasValue
com.vaadin.flow.component.HasValue.ValueChangeEvent<V>, com.vaadin.flow.component.HasValue.ValueChangeListener<E extends com.vaadin.flow.component.HasValue.ValueChangeEvent<?>>Nested classes/interfaces inherited from interface com.vaadin.featurepack.data.Property
Property.Editor, Property.ReadOnlyException, Property.ReadOnlyStatusChangeEvent, Property.ReadOnlyStatusChangeListener, Property.ReadOnlyStatusChangeNotifier, Property.Transactional<T>, Property.ValueChangeListener, Property.ValueChangeNotifier, Property.Viewer -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidattach()Constructs the content and notifies it that theCustomFieldis attached to a window.protected voidfireEvent(com.vaadin.flow.component.ComponentEvent<?> componentEvent) voidfocus()Sets the focus to this component.Stream<com.vaadin.flow.component.Component> com.vaadin.flow.component.ComponentReturns the content (UI) of the custom component.com.vaadin.flow.dom.Elementprotected TintGets the tabulator index of theFocusablecomponent.protected abstract com.vaadin.flow.component.ComponentCreate the content component or layout for the field.Iterator<com.vaadin.flow.component.Component> iterator()Gets an iterator to the collection of contained components.protected voidonAttach(com.vaadin.flow.component.AttachEvent attachEvent) protected voidonDetach(com.vaadin.flow.component.DetachEvent detachEvent) voidsetFInternalValue(T newValue) voidsetFocusDelegate(Focusable focusDelegate) Sets the component to which all methods from theFocusableinterface should be delegated.voidsetHeight(float height, com.vaadin.flow.component.Unit unit) Sets the height of the object.voidClears any defined height.protected voidsetInternalValue(T newValue) voidsetLabelComponent(com.vaadin.flow.component.Component labelComponent) Sets the component's label component.protected voidsetPresentationValue(T value) voidSets the size to 100% x 100%.voidClears any size settings.voidsetTabIndex(int tabIndex) Sets the tabulator index of theFocusablecomponent.voidsetWidth(float width, com.vaadin.flow.component.Unit unit) Sets the width of the object.voidClears any defined width.voidvalidate()Checks the validity of the validatable.Methods inherited from class com.vaadin.flow.component.AbstractCompositeField
addValueChangeListener, bindValue, getEmptyValue, getValue, isEmpty, setModelValue, setValue, valueEqualsMethods inherited from class com.vaadin.flow.component.Component
addListener, bindVisible, findAncestor, findAncestor, from, get, getEventBus, getId, getListeners, getLocale, getParent, getTestId, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getUI, getUIOrThrow, hasListener, isAttached, isTemplateMapped, isVisible, onEnabledStateChanged, removeFromParent, scrollIntoView, scrollIntoView, set, setElement, setId, setTestId, setVisible, whenAttachedMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.vaadin.flow.component.AttachNotifier
addAttachListenerMethods inherited from interface com.vaadin.flow.component.BlurNotifier
addBlurListenerMethods inherited from interface com.vaadin.flow.component.DetachNotifier
addDetachListenerMethods inherited from interface com.vaadin.featurepack.server.FAbstractClientConnector
addLegacyAttachListener, addLegacyDetachListener, addListener, addListener, detach, doConnectorOnAttach, doConnectorOnDetach, fireEvent, fireEvent, getAllChildrenIterable, getFListeners, getFlowComponent, getResource, hasListeners, isAttached, isConnectorEnabled, markAsDirty, markAsDirtyRecursive, removeAttachListener, removeDetachListener, removeListener, removeListener, setResourceMethods inherited from interface com.vaadin.featurepack.ui.FAbstractComponent
addContextClickListener, addListener, addShortcutListener, addStyleName, addStyleNames, beforeClientResponse, getCaption, getComponentError, getData, getDescription, getFErrorIndicator, getFErrorMessage, getFId, getFParent, getIcon, getIconResource, getPrimaryStyleName, getStyleName, isCaptionAsHtml, isImmediate, isResponsive, notifyParentAboutStyleChanges, removeContextClickListener, removeShortcutListener, removeStyleName, removeStyleNames, setCaption, setCaptionAsHtml, setComponentError, setData, setDescription, setDescription, setIcon, setIcon, setIconResource, setImmediate, setLocale, setPrimaryStyleName, setResponsive, setStyleName, setStyleNameMethods inherited from interface com.vaadin.featurepack.data.ui.Field
addReadOnlyStatusChangeListener, addValidator, addValueChangeListener, commit, discard, getConvertedValue, getConverter, getFAbstractField, getPropertyDataSource, getRequiredError, getType, getValidators, isBuffered, isEmpty, isInvalidAllowed, isInvalidCommitted, isModified, isPropertyReadOnly, isRequired, isValid, readOnlyStatusChange, removeAllValidators, removeReadOnlyStatusChangeListener, removeValidator, removeValueChangeListener, setBuffered, setConverter, setInvalidAllowed, setInvalidCommitted, setPropertyDataSource, setPropertyReadOnly, setRequired, setRequiredError, valueChangeMethods inherited from interface com.vaadin.flow.component.Focusable
addFocusShortcut, blur, focusMethods inherited from interface com.vaadin.flow.component.FocusNotifier
addFocusListenerMethods inherited from interface com.vaadin.flow.component.HasEnabled
bindEnabled, isEnabled, setEnabledMethods inherited from interface com.vaadin.flow.component.HasSize
bindHeight, bindWidth, getHeight, getHeightUnit, getMaxHeight, getMaxWidth, getMinHeight, getMinWidth, getWidth, getWidthUnit, setMaxHeight, setMaxHeight, setMaxWidth, setMaxWidth, setMinHeight, setMinHeight, setMinWidth, setMinWidthMethods inherited from interface com.vaadin.featurepack.server.HasSizeable
getFHeight, getFWidth, getHeightUnits, getWidthUnits, setHeight, setHeightFull, setWidth, setWidthFullMethods inherited from interface com.vaadin.flow.component.HasStyle
addClassName, addClassNames, bindClassName, bindClassNames, getClassName, getClassNames, getStyle, hasClassName, removeClassName, removeClassNames, setClassName, setClassNameMethods inherited from interface com.vaadin.flow.component.HasValue
addValueChangeListener, bindValue, clear, getEmptyValue, getOptionalValue, getValue, isEmpty, setValueMethods inherited from interface com.vaadin.flow.component.HasValueAndElement
bindReadOnly, bindRequiredIndicatorVisible, isReadOnly, isRequiredIndicatorVisible, setReadOnly, setRequiredIndicatorVisibleMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
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:
onAttachin classcom.vaadin.flow.component.Component
-
onDetach
protected void onDetach(com.vaadin.flow.component.DetachEvent detachEvent) - Overrides:
onDetachin classcom.vaadin.flow.component.Component
-
setLabelComponent
public void setLabelComponent(com.vaadin.flow.component.Component labelComponent) Description copied from interface:FAbstractComponentSets the component's label component. Flow components that support caption component usually overrides this.- Specified by:
setLabelComponentin interfaceFAbstractComponent- Parameters:
labelComponent- the new label component for the component.
-
attach
public void attach()Constructs the content and notifies it that theCustomFieldis attached to a window.- Specified by:
attachin interfaceClientConnector- Specified by:
attachin interfaceFAbstractClientConnector
-
getContent
public com.vaadin.flow.component.Component getContent()Returns the content (UI) of the custom component.- Overrides:
getContentin classcom.vaadin.flow.component.Composite<com.vaadin.flow.component.Component>- Returns:
- Component
-
getElement
public com.vaadin.flow.dom.Element getElement()- Specified by:
getElementin interfacecom.vaadin.flow.component.HasElement- Overrides:
getElementin classcom.vaadin.flow.component.Composite<com.vaadin.flow.component.Component>
-
getChildren
- Overrides:
getChildrenin classcom.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 ofCustomFieldshould 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 aCustomField.- Overrides:
initContentin classcom.vaadin.flow.component.Composite<com.vaadin.flow.component.Component>- Returns:
Componentrepresenting the UI of the CustomField
-
setHeight
public void setHeight(float height, com.vaadin.flow.component.Unit unit) Description copied from interface:FSizeableSets the height of the object. Negative number implies unspecified size (terminal is free to set the size).- Specified by:
setHeightin interfaceFSizeable- Specified by:
setHeightin interfacecom.vaadin.flow.component.HasSize- Specified by:
setHeightin interfaceHasSizeable- 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:FSizeableSets the width of the object. Negative number implies unspecified size (terminal is free to set the size).- Specified by:
setWidthin interfaceFSizeable- Specified by:
setWidthin interfacecom.vaadin.flow.component.HasSize- Specified by:
setWidthin interfaceHasSizeable- Parameters:
width- the width of the object.unit- the unit used for the width.
-
setSizeFull
public void setSizeFull()Description copied from interface:FSizeableSets the size to 100% x 100%.- Specified by:
setSizeFullin interfaceFSizeable- Specified by:
setSizeFullin interfacecom.vaadin.flow.component.HasSize- Specified by:
setSizeFullin interfaceHasSizeable
-
setSizeUndefined
public void setSizeUndefined()Description copied from interface:FSizeableClears any size settings.- Specified by:
setSizeUndefinedin interfaceFSizeable- Specified by:
setSizeUndefinedin interfacecom.vaadin.flow.component.HasSize- Specified by:
setSizeUndefinedin interfaceHasSizeable
-
setWidthUndefined
public void setWidthUndefined()Description copied from interface:FSizeableClears any defined width.- Specified by:
setWidthUndefinedin interfaceFSizeable- Specified by:
setWidthUndefinedin interfaceHasSizeable
-
setHeightUndefined
public void setHeightUndefined()Description copied from interface:FSizeableClears any defined height.- Specified by:
setHeightUndefinedin interfaceFSizeable- Specified by:
setHeightUndefinedin interfaceHasSizeable
-
iterator
Description copied from interface:HasComponentsGets 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:
iteratorin interfaceHasComponents- Specified by:
iteratorin interfaceIterable<T>- Returns:
- the component iterator.
-
setFocusDelegate
Sets the component to which all methods from theFocusableinterface 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,
Focusableevents 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:FocusableSets the focus to this component. -
getTabIndex
public int getTabIndex()Description copied from interface:FocusableGets the tabulator index of theFocusablecomponent.- Specified by:
getTabIndexin interfaceFocusable- Specified by:
getTabIndexin interfacecom.vaadin.flow.component.Focusable<T>- Returns:
- tab index set for the
Focusablecomponent - See Also:
-
setTabIndex
public void setTabIndex(int tabIndex) Description copied from interface:FocusableSets the tabulator index of theFocusablecomponent. 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:
setTabIndexin interfaceFocusable- Specified by:
setTabIndexin interfacecom.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
Description copied from interface:ValidatableChecks 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:
validatein interfaceValidatable- Throws:
Validator.InvalidValueException- if the value is not valid
-
setPresentationValue
- Specified by:
setPresentationValuein classcom.vaadin.flow.component.AbstractCompositeField<com.vaadin.flow.component.Component,CustomField<T>, T>
-
getInternalValue
-
setInternalValue
-
getFInternalValue
- Specified by:
getFInternalValuein interfaceHasFInternalValue<T>
-
setFInternalValue
- Specified by:
setFInternalValuein interfaceHasFInternalValue<T>
-
fireEvent
protected void fireEvent(com.vaadin.flow.component.ComponentEvent<?> componentEvent) - Overrides:
fireEventin classcom.vaadin.flow.component.Component
-