com.vaadin.ui.AbstractField. It is provided for
compatibility and migration purposes. As of 8.0, new field
implementations should extend the new
AbstractField instead.@Deprecated public abstract class AbstractField<T> extends AbstractLegacyComponent implements Field<T>, Property.ReadOnlyStatusChangeListener, Property.ReadOnlyStatusChangeNotifier, Action.ShortcutNotifier
Abstract field component for implementing buffered property editors. The
field may hold an internal value, or it may be connected to any data source
that implements the Property interface. AbstractField
implements that interface itself, too, so accessing the Property value
represented by it is straightforward.
AbstractField also provides the Buffered interface for buffering the
data source value. By default the Field is in write through-mode and
#setWriteThrough(boolean)should be called to enable buffering.
The class also supports validators to make sure the value
contained in the field is valid.
| Modifier and Type | Class and Description |
|---|---|
static class |
AbstractField.FocusShortcut
Deprecated.
Replaced in 8.0 with
FocusShortcut |
static class |
AbstractField.ReadOnlyStatusChangeEvent
Deprecated.
|
Field.ValueChangeEventComponent.ErrorEvent, Component.Event, Component.Focusable, Component.ListenerClientConnector.AttachEvent, ClientConnector.AttachListener, ClientConnector.ConnectorErrorEvent, ClientConnector.DetachEvent, ClientConnector.DetachListenerSizeable.UnitBuffered.SourceExceptionProperty.Editor, Property.ReadOnlyException, Property.ReadOnlyStatusChangeListener, Property.ReadOnlyStatusChangeNotifier, Property.Transactional<T>, Property.ValueChangeListener, Property.ValueChangeNotifier, Property.ViewerDESIGN_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 |
|---|
AbstractField()
Deprecated.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addListener(Property.ReadOnlyStatusChangeListener listener)
Deprecated.
As of 7.0, replaced by
addReadOnlyStatusChangeListener(Property.ReadOnlyStatusChangeListener) |
void |
addListener(Property.ValueChangeListener listener)
Deprecated.
As of 7.0, replaced by
addValueChangeListener(Property.ValueChangeListener) |
void |
addReadOnlyStatusChangeListener(Property.ReadOnlyStatusChangeListener listener)
Deprecated.
Registers a new read-only status change listener for this Property.
|
void |
addValidator(Validator validator)
Deprecated.
Adds a new validator for the field's value.
|
void |
addValueChangeListener(Property.ValueChangeListener listener)
Deprecated.
Registers a new value change listener for this Property.
|
void |
attach()
Deprecated.
Notifies the component that it is connected to an application.
|
void |
beforeClientResponse(boolean initial)
Deprecated.
|
void |
clear()
Deprecated.
Clears the value of the field.
|
void |
commit()
Deprecated.
Updates all changes since the previous commit to the data source.
|
void |
detach()
Deprecated.
|
void |
discard()
Deprecated.
Discards all changes since last commit.
|
protected void |
fireReadOnlyStatusChange()
Deprecated.
Emits the read-only status change event.
|
protected void |
fireValueChange(boolean repaintIsNotNeeded)
Deprecated.
Emits the value change event.
|
void |
focus()
Deprecated.
|
String |
getConversionError()
Deprecated.
Gets the error that is shown if the field value cannot be converted to
the data source type.
|
protected String |
getConversionError(Class<?> dataSourceType,
Converter.ConversionException e)
Deprecated.
Returns the conversion error with {0} replaced by the data source type
and {1} replaced by the exception (localized) message.
|
Object |
getConvertedValue()
Deprecated.
Returns the current value (as returned by
getValue()) converted
to the data source type. |
Converter<T,Object> |
getConverter()
Deprecated.
Gets the converter used to convert the property data source value to the
field value.
|
protected Buffered.SourceException |
getCurrentBufferedSourceException()
Deprecated.
Gets the current buffered source exception.
|
protected Collection<String> |
getCustomAttributes()
Deprecated.
|
ErrorMessage |
getErrorMessage()
Deprecated.
Error messages shown by the fields are composites of the error message
thrown by the superclasses (that is the component error message),
validation errors and buffered source errors.
|
protected T |
getInternalValue()
Deprecated.
Returns the internal field value, which might not match the data source
value e.g.
|
protected Class<?> |
getModelType()
Deprecated.
Retrieves the type of the currently used data model.
|
Property |
getPropertyDataSource()
Deprecated.
Gets the current data source of the field, if any.
|
String |
getRequiredError()
Deprecated.
Gets the error message that is to be displayed if a required field is
empty.
|
protected AbstractFieldState |
getState()
Deprecated.
|
protected AbstractFieldState |
getState(boolean markAsDirty)
Deprecated.
|
int |
getTabIndex()
Deprecated.
|
abstract Class<? extends T> |
getType()
Deprecated.
Returns the type of the Field.
|
Collection<Validator> |
getValidators()
Deprecated.
Gets the validators of the field.
|
T |
getValue()
Deprecated.
Gets the current value of the field.
|
boolean |
isBuffered()
Deprecated.
Checks the buffered mode of this Field.
|
boolean |
isEmpty()
Deprecated.
Is the field empty?
In general, "empty" state is same as null.
|
boolean |
isInvalidAllowed()
Deprecated.
Fields allow invalid values by default.
|
boolean |
isInvalidCommitted()
Deprecated.
Tests if the invalid data is committed to datasource.
|
boolean |
isModified()
Deprecated.
Tests if the value stored in the object has been modified since it was
last updated from the data source.
|
boolean |
isReadOnly()
Deprecated.
The abstract field is read only also if the data source is in read only
mode.
|
boolean |
isRequired()
Deprecated.
Is this field required.
|
boolean |
isValid()
Deprecated.
Tests the current value against registered validators if the field is not
empty.
|
boolean |
isValidationVisible()
Deprecated.
Is automatic, visible validation enabled?
If automatic validation is enabled, any validators connected to this
component are evaluated while painting the component and potential error
messages are sent to client.
|
void |
readDesign(org.jsoup.nodes.Element design,
DesignContext designContext)
Deprecated.
|
void |
readOnlyStatusChange(Property.ReadOnlyStatusChangeEvent event)
Deprecated.
React to read only status changes of the property by requesting a
repaint.
|
void |
removeAllValidators()
Deprecated.
Removes all validators from the field.
|
void |
removeListener(Property.ReadOnlyStatusChangeListener listener)
Deprecated.
As of 7.0, replaced by
removeReadOnlyStatusChangeListener(Property.ReadOnlyStatusChangeListener) |
void |
removeListener(Property.ValueChangeListener listener)
Deprecated.
As of 7.0, replaced by
removeValueChangeListener(Property.ValueChangeListener) |
void |
removeReadOnlyStatusChangeListener(Property.ReadOnlyStatusChangeListener listener)
Deprecated.
Removes a previously registered read-only status change listener.
|
void |
removeValidator(Validator validator)
Deprecated.
Removes the validator from the field.
|
void |
removeValueChangeListener(Property.ValueChangeListener listener)
Deprecated.
Removes a previously registered value change listener.
|
void |
setBuffered(boolean buffered)
Deprecated.
Sets the buffered mode of this Field.
|
void |
setConversionError(String valueConversionError)
Deprecated.
Sets the error that is shown if the field value cannot be converted to
the data source type.
|
void |
setConvertedValue(Object value)
Deprecated.
Sets the value of the field using a value of the data source type.
|
void |
setConverter(Class<?> datamodelType)
Deprecated.
Retrieves a converter for the field from the converter factory defined
for the application.
|
void |
setConverter(Converter<T,?> converter)
Deprecated.
Sets the converter used to convert the field value to property data
source type.
|
void |
setCurrentBufferedSourceException(Buffered.SourceException currentBufferedSourceException)
Deprecated.
Sets the current buffered source exception.
|
protected void |
setInternalValue(T newValue)
Deprecated.
Sets the internal field value.
|
void |
setInvalidAllowed(boolean invalidAllowed)
Deprecated.
Fields allow invalid values by default.
|
void |
setInvalidCommitted(boolean isCommitted)
Deprecated.
Sets if the invalid data should be committed to datasource.
|
void |
setLocale(Locale locale)
Deprecated.
|
void |
setPropertyDataSource(Property newDataSource)
Deprecated.
Sets the specified Property as the data source for the field.
|
void |
setReadOnly(boolean readOnly)
Deprecated.
Changes the readonly state and throw read-only status change events.
|
void |
setRequired(boolean required)
Deprecated.
Sets the field required.
|
void |
setRequiredError(String requiredMessage)
Deprecated.
Set the error that is show if this field is required, but empty.
|
void |
setTabIndex(int tabIndex)
Deprecated.
|
void |
setValidationVisible(boolean validateAutomatically)
Deprecated.
Enable or disable automatic, visible validation.
|
void |
setValue(T newFieldValue)
Deprecated.
Sets the value of the field.
|
protected void |
setValue(T newFieldValue,
boolean repaintIsNotNeeded)
Deprecated.
Sets the value of the field.
|
protected void |
setValue(T newFieldValue,
boolean repaintIsNotNeeded,
boolean ignoreReadOnly)
Deprecated.
Sets the value of the field.
|
protected boolean |
shouldHideErrors()
Deprecated.
Returns true if the error indicator be hidden when painting the component
even when there are errors.
|
void |
validate()
Deprecated.
Checks the validity of the Field.
|
protected void |
validate(T fieldValue)
Deprecated.
Validates that the given value pass the validators for the field.
|
void |
valueChange(Property.ValueChangeEvent event)
Deprecated.
This method listens to data source value changes and passes the changes
forwards.
|
void |
writeDesign(org.jsoup.nodes.Element design,
DesignContext designContext)
Deprecated.
|
getExplicitImmediateValue, isImmediate, setImmediateaddContextClickListener, addListener, addShortcutListener, addStyleName, findAncestor, fireComponentErrorEvent, fireComponentEvent, getActionManager, getCaption, getComponentError, getData, getDebugId, getDescription, getHeight, getHeightUnits, getIcon, getId, getLocale, getParent, getPrimaryStyleName, getStyleName, getWidth, getWidthUnits, isCaptionAsHtml, isConnectorEnabled, isEnabled, isOrHasAncestor, isRequiredIndicatorVisible, isResponsive, isVisible, removeContextClickListener, removeListener, removeShortcutListener, removeStyleName, setCaption, setCaptionAsHtml, setComponentError, setData, setDebugId, setDescription, setDescription, setEnabled, setHeight, setHeight, setHeightUndefined, setIcon, setId, setParent, setPrimaryStyleName, setRequiredIndicatorVisible, setResponsive, setSizeFull, setSizeUndefined, setStyleName, setVisible, setWidth, setWidth, setWidthUndefinedaddAttachListener, addDetachListener, addExtension, 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, 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, removeListener, removeStyleName, removeStyleNames, setCaption, setEnabled, setIcon, setId, setParent, setPrimaryStyleName, setStyleName, setStyleName, setVisibleaddAttachListener, addDetachListener, encodeState, getErrorHandler, getExtensions, getRpcManager, getStateType, handleConnectorRequest, isAttached, isConnectorEnabled, markAsDirty, markAsDirtyRecursive, removeAttachListener, removeDetachListener, removeExtension, requestRepaint, requestRepaintAll, retrievePendingRpcCalls, setErrorHandlergetHeight, getHeightUnits, getWidth, getWidthUnits, setHeight, setHeight, setHeightUndefined, setSizeFull, setSizeUndefined, setWidth, setWidth, setWidthUndefinedaddShortcutListener, removeShortcutListenerprotected boolean shouldHideErrors()
public abstract Class<? extends T> getType()
getValue and
setValue must be compatible with this type: one must be able
to safely cast the value returned from getValue to the given
type and pass any variable assignable to this type as an argument to
setValue.public boolean isReadOnly()
isReadOnly in interface Property<T>isReadOnly in class AbstractLegacyComponenttrue if the component or any of its parents is in
read-only mode, false if not.AbstractLegacyComponent.setReadOnly(boolean)public void setReadOnly(boolean readOnly)
setReadOnly in interface Property<T>setReadOnly in class AbstractLegacyComponentreadOnly - a boolean value specifying whether the component is put
read-only mode or notcom.vaadin.ui.Component#setReadOnly(boolean)public boolean isInvalidCommitted()
isInvalidCommitted in interface BufferedValidatableBufferedValidatable.isInvalidCommitted()public void setInvalidCommitted(boolean isCommitted)
setInvalidCommitted in interface BufferedValidatableBufferedValidatable.setInvalidCommitted(boolean)public void commit()
throws Buffered.SourceException,
Validator.InvalidValueException
Bufferedcommit is called.commit in interface BufferedBuffered.SourceException - if the operation fails because of an exception is thrown by
the data source. The cause is included in the exception.Validator.InvalidValueException - if the operation fails because validation is enabled and the
values do not validatepublic void discard()
throws Buffered.SourceException
Buffereddiscard in interface BufferedBuffered.SourceException - if the operation fails because of an exception is thrown by
the data source. The cause is included in the exception.public boolean isModified()
BufferedisModified in interface Bufferedtrue if the value in the object has been modified
since the last data source update, false if not.public void setBuffered(boolean buffered)
When the field is in buffered mode, changes will not be committed to the
property data source until commit() is called.
Setting buffered mode from true to false will commit any pending changes.
setBuffered in interface Bufferedbuffered - true if buffered mode should be turned on, false otherwisepublic boolean isBuffered()
isBuffered in interface Bufferedpublic T getValue()
This is the visible, modified and possible invalid value the user have entered to the field.
Note that the object returned is compatible with getType(). For example,
if the type is String, this returns Strings even when the underlying
datasource is of some other type. In order to access the converted value,
use getConvertedValue() and to access the value of the property
data source, use Property.getValue() for the property data
source.
Since Vaadin 7.0, no implicit conversions between other data types and String are performed, but a converter is used if set.
public void setValue(T newFieldValue) throws Property.ReadOnlyException, Converter.ConversionException
setValue in interface Property<T>newFieldValue - the New value of the field.Property.ReadOnlyExceptionConverter.ConversionExceptionprotected void setValue(T newFieldValue, boolean repaintIsNotNeeded)
newFieldValue - the New value of the field.repaintIsNotNeeded - True if caller is sure that repaint is not needed.Property.ReadOnlyExceptionConverter.ConversionExceptionValidator.InvalidValueExceptionprotected void setValue(T newFieldValue, boolean repaintIsNotNeeded, boolean ignoreReadOnly) throws Property.ReadOnlyException, Converter.ConversionException, Validator.InvalidValueException
newFieldValue - the New value of the field.repaintIsNotNeeded - True if caller is sure that repaint is not needed.ignoreReadOnly - True if the read-only check should be ignoredProperty.ReadOnlyExceptionConverter.ConversionExceptionValidator.InvalidValueExceptionpublic Property getPropertyDataSource()
getPropertyDataSource in interface Property.Viewernull if
none defined.public void setPropertyDataSource(Property newDataSource)
Sets the specified Property as the data source for the field. All uncommitted changes are replaced with a value from the new data source.
If the datasource has any validators, the same validators are added to the field. Because the default behavior of the field is to allow invalid values, but not to allow committing them, this only adds visual error messages to fields and do not allow committing them as long as the value is invalid. After the value is valid, the error message is not shown and the commit can be done normally.
If the data source implements Property.ValueChangeNotifier and/or
Property.ReadOnlyStatusChangeNotifier, the field registers itself
as a listener and updates itself according to the events it receives. To
avoid memory leaks caused by references to a field no longer in use, the
listener registrations are removed on detach and re-added on attach.
Note: before 6.5 we actually called discard() method in the beginning of the method. This was removed to simplify implementation, avoid excess calls to backing property and to avoid odd value change events that were previously fired (developer expects 0-1 value change events if this method is called). Some complex field implementations might now need to override this method to do housekeeping similar to discard().
setPropertyDataSource in interface Property.ViewernewDataSource - the new data source Property.public void setConverter(Class<?> datamodelType)
datamodelType - The type of the data model that we want to be able to convert
fromprotected Class<?> getModelType()
protected String getConversionError(Class<?> dataSourceType, Converter.ConversionException e)
dataSourceType - the type of the data sourcee - a conversion exception which can provide additional
informationpublic Object getConvertedValue()
getValue()) converted
to the data source type.
This returns the same as getValue() if no converter
has been set. The value is not necessarily the same as the data source
value e.g. if the field is in buffered mode and has been modified.
public void setConvertedValue(Object value)
setValue(Object) is called.value - The value to set. Must be the same type as the data source.public void addValidator(Validator validator)
addValidator in interface Validatablevalidator - the new validator to be added.public Collection<Validator> getValidators()
getValidators in interface Validatablepublic void removeValidator(Validator validator)
removeValidator in interface Validatablevalidator - the validator to remove.public void removeAllValidators()
removeAllValidators in interface Validatablepublic boolean isValid()
validate() should be used instead of
isValid() to also get the error message.isValid in interface Validatabletrue if all registered validators claim that the
current value is valid or if the field is empty and not required,
false otherwise.public void validate()
throws Validator.InvalidValueException
setRequired(boolean) and is empty, if one or several of the
validators added to the field indicate it is invalid or if the value
cannot be converted provided a converter has been set.
The "required" validation is a built-in validation feature. If the field
is required and empty this method throws an EmptyValueException with the
error message set using setRequiredError(String).validate in interface ValidatableValidator.InvalidValueException - if the value is not validValidatable.validate()protected void validate(T fieldValue) throws Validator.InvalidValueException
This method does not check the requiredness of the field.
fieldValue - The value to checkValidator.InvalidValueException - if one or several validators failpublic boolean isInvalidAllowed()
isInvalidAllowed in interface ValidatableValidatable.isInvalidAllowed()public void setInvalidAllowed(boolean invalidAllowed)
throws UnsupportedOperationException
In common setting where the user wants to assure the correctness of the datasource, but allow temporarily invalid contents in the field, the user should add the validators to datasource, that should not allow invalid values. The validators are automatically copied to the field when the datasource is set.
setInvalidAllowed in interface ValidatableUnsupportedOperationException - if the setInvalidAllowed is not supported.Validatable.setInvalidAllowed(boolean)public ErrorMessage getErrorMessage()
getErrorMessage in class AbstractComponentAbstractComponent.getErrorMessage()public void addValueChangeListener(Property.ValueChangeListener listener)
Property.ValueChangeNotifieraddValueChangeListener in interface Property.ValueChangeNotifierlistener - the new Listener to be registered@Deprecated public void addListener(Property.ValueChangeListener listener)
addValueChangeListener(Property.ValueChangeListener)addListener in interface Property.ValueChangeNotifierpublic void removeValueChangeListener(Property.ValueChangeListener listener)
Property.ValueChangeNotifierremoveValueChangeListener in interface Property.ValueChangeNotifierlistener - listener to be removed@Deprecated public void removeListener(Property.ValueChangeListener listener)
removeValueChangeListener(Property.ValueChangeListener)removeListener in interface Property.ValueChangeNotifierprotected void fireValueChange(boolean repaintIsNotNeeded)
public void readOnlyStatusChange(Property.ReadOnlyStatusChangeEvent event)
readOnlyStatusChange in interface Property.ReadOnlyStatusChangeListenerevent - Read-only status change event objectProperty.ReadOnlyStatusChangeListenerpublic void addReadOnlyStatusChangeListener(Property.ReadOnlyStatusChangeListener listener)
Property.ReadOnlyStatusChangeNotifieraddReadOnlyStatusChangeListener in interface Property.ReadOnlyStatusChangeNotifierlistener - the new Listener to be registered@Deprecated public void addListener(Property.ReadOnlyStatusChangeListener listener)
addReadOnlyStatusChangeListener(Property.ReadOnlyStatusChangeListener)addListener in interface Property.ReadOnlyStatusChangeNotifierpublic void removeReadOnlyStatusChangeListener(Property.ReadOnlyStatusChangeListener listener)
Property.ReadOnlyStatusChangeNotifierremoveReadOnlyStatusChangeListener in interface Property.ReadOnlyStatusChangeNotifierlistener - listener to be removed@Deprecated public void removeListener(Property.ReadOnlyStatusChangeListener listener)
removeReadOnlyStatusChangeListener(Property.ReadOnlyStatusChangeListener)removeListener in interface Property.ReadOnlyStatusChangeNotifierprotected void fireReadOnlyStatusChange()
public void valueChange(Property.ValueChangeEvent event)
valueChange in interface Property.ValueChangeListenerevent - the value change event telling the data source contents have
changed.public void focus()
focus in interface Component.Focusablefocus in class AbstractComponentpublic int getTabIndex()
getTabIndex in interface Component.Focusablepublic void setTabIndex(int tabIndex)
setTabIndex in interface Component.Focusableprotected T getInternalValue()
setInternalValue(Object) to compute internal field value at
runtime. When doing so, typically also isModified() needs to be
overridden and care should be taken in the management of the empty state
and buffering support.protected void setInternalValue(T newValue)
getInternalValue() if necessary.newValue - the new value to be set.public void attach()
attach in interface ClientConnectorattach in interface Componentattach in class AbstractComponentComponent.attach()public void setLocale(Locale locale)
setLocale in class AbstractComponentpublic void detach()
detach in interface ClientConnectordetach in class AbstractComponentpublic boolean isRequired()
FieldisRequired in interface Field<T>true if the field is required,otherwise
false.public void setRequired(boolean required)
FieldsetRequired in interface Field<T>required - Is the field required.public void setRequiredError(String requiredMessage)
setRequiredError in interface Field<T>requiredMessage - Message to be shown when this field is required, but empty.public String getRequiredError()
FieldgetRequiredError in interface Field<T>public String getConversionError()
public void setConversionError(String valueConversionError)
valueConversionError - Message to be shown when conversion of the value failspublic boolean isEmpty()
Fieldpublic void clear()
Field
The field value is typically reset to the initial value of the field.
Calling Field.isEmpty() on a cleared field must always returns true.
public boolean isValidationVisible()
public void setValidationVisible(boolean validateAutomatically)
validateAutomatically - True, if automatic validation is enabled.public void setCurrentBufferedSourceException(Buffered.SourceException currentBufferedSourceException)
currentBufferedSourceException - protected Buffered.SourceException getCurrentBufferedSourceException()
public Converter<T,Object> getConverter()
public void setConverter(Converter<T,?> converter)
converter - The new converter to use.protected AbstractFieldState getState()
getState in class AbstractLegacyComponentprotected AbstractFieldState getState(boolean markAsDirty)
getState in class AbstractLegacyComponentpublic void beforeClientResponse(boolean initial)
beforeClientResponse in interface ClientConnectorbeforeClientResponse in class AbstractLegacyComponentpublic void readDesign(org.jsoup.nodes.Element design,
DesignContext designContext)
readDesign in interface ComponentreadDesign in class AbstractLegacyComponentprotected Collection<String> getCustomAttributes()
getCustomAttributes in class AbstractComponentpublic void writeDesign(org.jsoup.nodes.Element design,
DesignContext designContext)
writeDesign in interface ComponentwriteDesign in class AbstractLegacyComponentCopyright © 2019 Vaadin Ltd. All rights reserved.