Class AbstractField<T>
- java.lang.Object
-
- com.vaadin.server.AbstractClientConnector
-
- com.vaadin.ui.AbstractComponent
-
- com.vaadin.ui.AbstractField<T>
-
- Type Parameters:
T- the input value type
- All Implemented Interfaces:
HasValue<T>,ContextClickEvent.ContextClickNotifier,MethodEventSource,ClientConnector,Sizeable,Connector,Component,Component.Focusable,Serializable
- Direct Known Subclasses:
AbstractColorPicker,AbstractDateField,AbstractTextField,CheckBox,ColorPickerGradient,ColorPickerGrid,CustomField,RichTextArea,Slider
public abstract class AbstractField<T> extends AbstractComponent implements HasValue<T>, Component.Focusable
An abstract implementation of a field, or aComponentallowing user input. ImplementsHasValueto represent the input value. Examples of typical field components include text fields, date pickers, and check boxes.This class replaces the Vaadin 7
com.vaadin.ui.AbstractFieldclass. The oldAbstractFieldis retained, under the new namecom.vaadin.v7.ui.AbstractField, for compatibility and migration purposes.- Since:
- 8.0
- Author:
- Vaadin Ltd.
- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface com.vaadin.server.ClientConnector
ClientConnector.AttachEvent, ClientConnector.AttachListener, ClientConnector.ConnectorErrorEvent, ClientConnector.DetachEvent, ClientConnector.DetachListener
-
Nested classes/interfaces inherited from interface com.vaadin.ui.Component
Component.ErrorEvent, Component.Event, Component.Focusable, Component.Listener
-
Nested classes/interfaces inherited from interface com.vaadin.data.HasValue
HasValue.ValueChangeEvent<V>, HasValue.ValueChangeListener<V>
-
Nested classes/interfaces inherited from interface com.vaadin.server.Sizeable
Sizeable.Unit
-
-
Field Summary
-
Fields inherited from class com.vaadin.ui.AbstractComponent
DESIGN_ATTR_PLAIN_TEXT
-
Fields inherited from interface com.vaadin.server.Sizeable
SIZE_UNDEFINED, UNITS_CM, UNITS_EM, UNITS_EX, UNITS_INCH, UNITS_MM, UNITS_PERCENTAGE, UNITS_PICAS, UNITS_PIXELS, UNITS_POINTS
-
-
Constructor Summary
Constructors Constructor Description AbstractField()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description RegistrationaddValueChangeListener(HasValue.ValueChangeListener<T> listener)Adds a value change listener.protected HasValue.ValueChangeEvent<T>createValueChange(T oldValue, boolean userOriginated)Returns a new value change event instance.protected abstract voiddoSetValue(T value)Sets the value of this field.voidfocus()Sets the focus for this component if the component isComponent.Focusable.protected Collection<String>getCustomAttributes()Returns a collection of attributes that should not be handled by the basic implementation of theAbstractComponent.readDesign(Element, DesignContext)andAbstractComponent.writeDesign(Element, DesignContext)methods.protected AbstractFieldStategetState()Returns the shared state bean with information to be sent from the server to the client.protected AbstractFieldStategetState(boolean markAsDirty)Returns the shared state for this connector.intgetTabIndex()Gets the tabulator index of theFocusablecomponent.protected booleanisDifferentValue(T newValue)Called when a new value is set to determine whether the provided new value is considered to be a change compared to the current value.booleanisReadOnly()Returns the read-only status from the state of thisAbstractComponent.booleanisRequiredIndicatorVisible()Checks whether the required indicator is visible or not.voidreadDesign(org.jsoup.nodes.Element design, DesignContext designContext)Reads the component state from the given design.voidsetReadOnly(boolean readOnly)Sets the read-only status in the state of thisAbstractComponent.voidsetRequiredIndicatorVisible(boolean visible)Sets the visibility of the required indicator.voidsetTabIndex(int tabIndex)Sets the tabulator index of theFocusablecomponent.voidsetValue(T value)Sets the value of this object.protected booleansetValue(T value, boolean userOriginated)Sets the value of this field if it has changed and fires a value change event.voidwriteDesign(org.jsoup.nodes.Element design, DesignContext designContext)Writes the component state to the given design.-
Methods inherited from class com.vaadin.ui.AbstractComponent
addContextClickListener, addListener, addShortcutListener, addStyleName, attach, 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, setHeight, setHeightFull, setHeightUndefined, setIcon, setId, setLocale, setParent, setPrimaryStyleName, setResponsive, setSizeFull, setSizeUndefined, setStyleName, setVisible, setWidth, setWidth, setWidthFull, setWidthUndefined
-
Methods inherited from class com.vaadin.server.AbstractClientConnector
addAttachListener, 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, updateDiffstate
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.vaadin.server.ClientConnector
addAttachListener, addDetachListener, beforeClientResponse, detach, encodeState, getErrorHandler, getExtensions, getRpcManager, getStateType, handleConnectorRequest, isAttached, isConnectorEnabled, markAsDirty, markAsDirtyRecursive, removeAttachListener, removeDetachListener, removeExtension, requestRepaint, requestRepaintAll, retrievePendingRpcCalls, setErrorHandler
-
Methods inherited from interface com.vaadin.ui.Component
addListener, addStyleName, addStyleNames, attach, getCaption, getDescription, getIcon, getId, getLocale, getParent, getPrimaryStyleName, getStyleName, getUI, isEnabled, isVisible, removeListener, removeStyleName, removeStyleNames, setCaption, setEnabled, setIcon, setId, setParent, setPrimaryStyleName, setStyleName, setStyleName, setVisible
-
Methods inherited from interface com.vaadin.shared.Connector
getConnectorId
-
Methods inherited from interface com.vaadin.data.HasValue
clear, getDefaultValidator, getEmptyValue, getOptionalValue, getValue, isEmpty
-
Methods inherited from interface com.vaadin.server.Sizeable
getHeight, getHeightUnits, getWidth, getWidthUnits, setHeight, setHeight, setHeightFull, setHeightUndefined, setSizeFull, setSizeUndefined, setWidth, setWidth, setWidthFull, setWidthUndefined
-
-
-
-
Method Detail
-
setValue
public void setValue(T value)
Description copied from interface:HasValueSets the value of this object. If the new value is not equal togetValue(), fires a value change event. May throwIllegalArgumentExceptionif the value is not acceptable.Implementation note: the implementing class should document whether null values are accepted or not.
-
isReadOnly
public boolean isReadOnly()
Description copied from class:AbstractComponentReturns the read-only status from the state of thisAbstractComponent. This method should be made public inComponentsthat implementHasValue.- Specified by:
isReadOnlyin interfaceHasValue<T>- Overrides:
isReadOnlyin classAbstractComponent- Returns:
trueif state has read-only on;falseif not- See Also:
AbstractComponent.setReadOnly(boolean)
-
setReadOnly
public void setReadOnly(boolean readOnly)
Sets the read-only status in the state of thisAbstractComponent. This method should be made public inComponentsthat implementHasValue.The server ignores (potentially forged) value change requests from the client to fields that are read-only. Programmatically changing the field value via
setValue(Object)is still possible.The read-only mode is distinct from the disabled state. When disabled, a component cannot be interacted with at all, and its content should be considered irrelevant or not applicable. In contrast, the user should still be able to read the content and otherwise interact with a read-only field even though changing the value is disallowed.
- Specified by:
setReadOnlyin interfaceHasValue<T>- Overrides:
setReadOnlyin classAbstractComponent- Parameters:
readOnly-trueto set read-only mode,falseotherwise.
-
addValueChangeListener
public Registration addValueChangeListener(HasValue.ValueChangeListener<T> listener)
Description copied from interface:HasValueAdds a value change listener. The listener is called when the value of thisHasValueis changed either by the user or programmatically.- Specified by:
addValueChangeListenerin interfaceHasValue<T>- Parameters:
listener- the value change listener, not null- Returns:
- a registration for the listener
-
readDesign
public void readDesign(org.jsoup.nodes.Element design, DesignContext designContext)Description copied from interface:ComponentReads the component state from the given design.The component is responsible not only for updating its own state but also for ensuring that its children update their state based on the design.
It is assumed that the component is in its default state when this method is called. Reading should only take into consideration attributes specified in the design and not reset any unspecified attributes to their defaults.
This method must not modify the design.
- Specified by:
readDesignin interfaceComponent- Overrides:
readDesignin classAbstractComponent- Parameters:
design- The element to obtain the state fromdesignContext- The DesignContext instance used for parsing the design
-
writeDesign
public void writeDesign(org.jsoup.nodes.Element design, DesignContext designContext)Description copied from interface:ComponentWrites the component state to the given design.The component is responsible not only for writing its own state but also for ensuring that its children write their state to the design.
This method must not modify the component state.
- Specified by:
writeDesignin interfaceComponent- Overrides:
writeDesignin classAbstractComponent- Parameters:
design- The element to write the component state to. Any previous attributes or child nodes are not cleared.designContext- The DesignContext instance used for writing the design
-
getCustomAttributes
protected Collection<String> getCustomAttributes()
Description copied from class:AbstractComponentReturns a collection of attributes that should not be handled by the basic implementation of theAbstractComponent.readDesign(Element, DesignContext)andAbstractComponent.writeDesign(Element, DesignContext)methods. Typically these are handled in a custom way in the overridden versions of the above methods- Overrides:
getCustomAttributesin classAbstractComponent- Returns:
- the collection of attributes that are not handled by the basic implementation
-
setValue
protected boolean setValue(T value, boolean userOriginated)
Sets the value of this field if it has changed and fires a value change event. If the value originates from the client and this field is read-only, does nothing. InvokesdoSetValueto actually store the value.- Parameters:
value- the new value to setuserOriginated-trueif this event originates from the client,falseotherwise.- Returns:
trueif the value was updated,falseotherwise
-
isDifferentValue
protected boolean isDifferentValue(T newValue)
Called when a new value is set to determine whether the provided new value is considered to be a change compared to the current value. This is used to determine whetherdoSetValue(Object)should be called and a value change event fired.- Parameters:
newValue- the new value candidate to check, may benull- Returns:
trueif the provided value is considered to be different and a value change event should be fired;falseif the values are considered to be the same and no value change should be fired
-
doSetValue
protected abstract void doSetValue(T value)
Sets the value of this field. May do sanitization or throwIllegalArgumentExceptionif the value is invalid. Typically saves the value to shared state.- Parameters:
value- the new value of the field- Throws:
IllegalArgumentException- if the value is invalid
-
createValueChange
protected HasValue.ValueChangeEvent<T> createValueChange(T oldValue, boolean userOriginated)
Returns a new value change event instance.- Parameters:
oldValue- the value of this field before this value change eventuserOriginated-trueif this event originates from the client,falseotherwise.- Returns:
- the new event
-
getState
protected AbstractFieldState getState()
Description copied from class:AbstractComponentReturns the shared state bean with information to be sent from the server to the client. Subclasses should override this method and set any relevant fields of the state returned by super.getState().- Overrides:
getStatein classAbstractComponent- Returns:
- updated component shared state
-
getState
protected AbstractFieldState getState(boolean markAsDirty)
Description copied from class:AbstractClientConnectorReturns the shared state for this connector.- Overrides:
getStatein classAbstractComponent- Parameters:
markAsDirty- true if the connector should automatically be marked dirty, false otherwise- Returns:
- The shared state for this connector. Never null.
- See Also:
AbstractClientConnector.getState()
-
focus
public void focus()
Description copied from class:AbstractComponentSets the focus for this component if the component isComponent.Focusable.- Specified by:
focusin interfaceComponent.Focusable- Overrides:
focusin classAbstractComponent- See Also:
FieldEvents,FieldEvents.FocusEvent,FieldEvents.FocusListener,FieldEvents.BlurEvent,FieldEvents.BlurListener
-
getTabIndex
public int getTabIndex()
Description copied from interface:Component.FocusableGets the tabulator index of theFocusablecomponent.- Specified by:
getTabIndexin interfaceComponent.Focusable- Returns:
- tab index set for the
Focusablecomponent - See Also:
Component.Focusable.setTabIndex(int)
-
setTabIndex
public void setTabIndex(int tabIndex)
Description copied from interface:Component.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.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.
- Specified by:
setTabIndexin interfaceComponent.Focusable- 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:
Component.Focusable.getTabIndex()
-
setRequiredIndicatorVisible
public void setRequiredIndicatorVisible(boolean visible)
Description copied from class:AbstractComponentSets the visibility of the required indicator. NOTE: Does not apply for all components!.If the component supports the required indicator (state extends
AbstractFieldState), then expose this method andAbstractComponent.isRequiredIndicatorVisible()aspublicin the component and call this method.This method will throw a
IllegalStateExceptionif the component state (returned byAbstractComponent.getState()) does not inheritAbstractFieldState.- Specified by:
setRequiredIndicatorVisiblein interfaceHasValue<T>- Overrides:
setRequiredIndicatorVisiblein classAbstractComponent- Parameters:
visible-trueto make the required indicator visible,falseif not
-
isRequiredIndicatorVisible
public boolean isRequiredIndicatorVisible()
Description copied from class:AbstractComponentChecks whether the required indicator is visible or not. NOTE: Does not apply for all components!.This method will throw a
IllegalStateExceptionif the component state (returned byAbstractComponent.getState()) does not inheritAbstractFieldState.- Specified by:
isRequiredIndicatorVisiblein interfaceHasValue<T>- Overrides:
isRequiredIndicatorVisiblein classAbstractComponent- Returns:
trueif visible,falseif not- See Also:
AbstractComponent.setRequiredIndicatorVisible(boolean)
-
-