T - field value typepublic abstract class CustomField<T> extends AbstractField<T> implements HasComponents
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 initContent().
Most custom fields can simply compose a user interface that calls the methods
AbstractField.doSetValue(Object) and HasValue.getValue() when necessary.
HasComponents.ComponentAttachDetachNotifier, HasComponents.ComponentAttachEvent, HasComponents.ComponentAttachListener, HasComponents.ComponentDetachEvent, HasComponents.ComponentDetachListenerComponent.ErrorEvent, Component.Event, Component.Focusable, Component.ListenerClientConnector.AttachEvent, ClientConnector.AttachListener, ClientConnector.ConnectorErrorEvent, ClientConnector.DetachEvent, ClientConnector.DetachListenerSizeable.UnitHasValue.ValueChangeEvent<V>, HasValue.ValueChangeListener<V>DESIGN_ATTR_PLAIN_TEXTSIZE_UNDEFINED, UNITS_CM, UNITS_EM, UNITS_EX, UNITS_INCH, UNITS_MM, UNITS_PERCENTAGE, UNITS_PICAS, UNITS_PIXELS, UNITS_POINTS| Constructor and Description |
|---|
CustomField()
Constructs a new custom field.
|
| Modifier and Type | Method and Description |
|---|---|
void |
attach()
Constructs the content and notifies it that the
CustomField is
attached to a window. |
void |
focus()
Sets the focus for this component if the component is
Focusable. |
protected Component |
getContent()
Returns the content (UI) of the custom component.
|
protected CustomFieldState |
getState()
Returns the shared state bean with information to be sent from the server
to the client.
|
protected CustomFieldState |
getState(boolean markAsDirty)
Returns the shared state for this connector.
|
int |
getTabIndex()
Gets the tabulator index of the
Focusable component. |
protected abstract Component |
initContent()
Create the content component or layout for the field.
|
Iterator<Component> |
iterator()
Gets an iterator to the collection of contained components.
|
void |
setFocusDelegate(Component.Focusable focusDelegate)
Sets the component to which all methods from the
Focusable
interface should be delegated. |
void |
setHeight(float height,
Sizeable.Unit unit)
Sets the height of the object.
|
void |
setTabIndex(int tabIndex)
Sets the tabulator index of the
Focusable component. |
void |
setWidth(float width,
Sizeable.Unit unit)
Sets the width of the object.
|
addValueChangeListener, createValueChange, doSetValue, getCustomAttributes, isDifferentValue, isReadOnly, isRequiredIndicatorVisible, readDesign, setReadOnly, setRequiredIndicatorVisible, setValue, setValue, writeDesignaddContextClickListener, addListener, addShortcutListener, addStyleName, beforeClientResponse, detach, findAncestor, fireComponentErrorEvent, fireComponentEvent, getActionManager, getCaption, getComponentError, getData, getDebugId, getDescription, getErrorMessage, getHeight, getHeightUnits, getIcon, getId, getLocale, getParent, getPrimaryStyleName, getStyleName, getWidth, getWidthUnits, isCaptionAsHtml, isConnectorEnabled, isEnabled, isOrHasAncestor, isResponsive, isVisible, removeContextClickListener, removeListener, removeShortcutListener, removeStyleName, setCaption, setCaptionAsHtml, setComponentError, setData, setDebugId, setDescription, setDescription, setEnabled, setHeight, setHeightFull, setHeightUndefined, setIcon, setId, setLocale, setParent, setPrimaryStyleName, setResponsive, setSizeFull, setSizeUndefined, setStyleName, setVisible, setWidth, setWidthFull, setWidthUndefinedaddAttachListener, addDetachListener, addExtension, addListener, addListener, addListener, addListener, addListener, addListener, addMethodInvocationToQueue, createState, encodeState, equals, fireEvent, getAllChildrenIterable, getConnectorId, getErrorHandler, getExtensions, getListeners, getResource, getRpcManager, getRpcProxy, getSession, getStateType, getUI, handleConnectorRequest, hashCode, hasListeners, isAttached, isThis, markAsDirty, markAsDirtyRecursive, registerRpc, registerRpc, removeAttachListener, removeDetachListener, removeExtension, removeListener, removeListener, removeListener, removeListener, removeListener, requestRepaint, requestRepaintAll, retrievePendingRpcCalls, setErrorHandler, setResource, updateDiffstateclone, finalize, getClass, notify, notifyAll, toString, wait, wait, waitaddListener, addStyleName, addStyleNames, getCaption, getDescription, getIcon, getId, getLocale, getParent, getPrimaryStyleName, getStyleName, getUI, isEnabled, isVisible, readDesign, removeListener, removeStyleName, removeStyleNames, setCaption, setEnabled, setIcon, setId, setParent, setPrimaryStyleName, setStyleName, setStyleName, setVisible, writeDesignaddAttachListener, addDetachListener, beforeClientResponse, detach, encodeState, getErrorHandler, getExtensions, getRpcManager, getStateType, handleConnectorRequest, isAttached, isConnectorEnabled, markAsDirty, markAsDirtyRecursive, removeAttachListener, removeDetachListener, removeExtension, requestRepaint, requestRepaintAll, retrievePendingRpcCalls, setErrorHandlergetConnectorIdgetHeight, getHeightUnits, getWidth, getWidthUnits, setHeight, setHeightFull, setHeightUndefined, setSizeFull, setSizeUndefined, setWidth, setWidthFull, setWidthUndefinedforEach, spliteratorclear, getDefaultValidator, getEmptyValue, getOptionalValue, getValue, isEmptypublic CustomField()
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.
public void attach()
CustomField is
attached to a window.attach in interface ClientConnectorattach in interface Componentattach in class AbstractComponentComponent.attach()protected Component getContent()
protected abstract Component initContent()
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.Component representing the UI of the CustomFieldpublic void setHeight(float height,
Sizeable.Unit unit)
SizeablesetHeight in interface SizeablesetHeight in class AbstractComponentheight - the height of the object.unit - the unit used for the width.public void setWidth(float width,
Sizeable.Unit unit)
SizeablesetWidth in interface SizeablesetWidth in class AbstractComponentwidth - the width of the object.unit - the unit used for the width.protected CustomFieldState getState()
AbstractComponentgetState in class AbstractField<T>protected CustomFieldState getState(boolean markAsDirty)
AbstractClientConnectorgetState in class AbstractField<T>markAsDirty - true if the connector should automatically be marked dirty,
false otherwiseAbstractClientConnector.getState()public Iterator<Component> iterator()
HasComponents
The iterator is typically unmodifiable, and calls to
Iterator.remove() throw an exception.
iterator in interface HasComponentsiterator in interface Iterable<Component>public void setFocusDelegate(Component.Focusable focusDelegate)
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.
focusDelegate - the focusable component to which focus events are redirectedpublic void focus()
AbstractComponentFocusable.focus in interface Component.Focusablefocus in class AbstractField<T>FieldEvents,
FieldEvents.FocusEvent,
FieldEvents.FocusListener,
FieldEvents.BlurEvent,
FieldEvents.BlurListenerpublic int getTabIndex()
Component.FocusableFocusable component.getTabIndex in interface Component.FocusablegetTabIndex in class AbstractField<T>Focusable componentComponent.Focusable.setTabIndex(int)public void setTabIndex(int tabIndex)
Component.FocusableFocusable 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.
Form loginBox = new Form();
loginBox.setCaption("Login");
layout.addComponent(loginBox);
// Create the first field which will be focused
TextField username = new TextField("User name");
loginBox.addField("username", username);
// Set focus to the user name
username.focus();
TextField password = new TextField("Password");
loginBox.addField("password", password);
Button login = new Button("Login");
loginBox.getFooter().addComponent(login);
// An additional component which natural focus order would
// be after the button.
CheckBox remember = new CheckBox("Remember me");
loginBox.getFooter().addComponent(remember);
username.setTabIndex(1);
password.setTabIndex(2);
remember.setTabIndex(3); // Different than natural place
login.setTabIndex(4);
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.
setTabIndex in interface Component.FocusablesetTabIndex in class AbstractField<T>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.Component.Focusable.getTabIndex()Copyright © 2022 Vaadin Ltd. All rights reserved.