Class AbstractField

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 com.itmill.toolkit.data.Property interface. AbstractField implements that interface itself, too, so accessing the Property value represented by it is straightforward.

AbstractField also provides the com.itmill.toolkit.data.Buffered interface for buffering the data source value. By default the Field is in write through-mode and com.itmill.toolkit.ui.AbstractField should be called to enable buffering.

The class also supports validators to make sure the value contained in the field is valid.

Synopsis

VERSION@

Since

3.0

Inheritance Path.  java.lang.Object-> com.itmill.toolkit.ui.AbstractComponent -> com.itmill.toolkit.ui.AbstractField

addListener(Property.ReadOnlyStatusChangeListener)

Parameters

listener

the new Listener to be registered

Description copied from interface: addListener

Registers a new read-only status change listener for this Property.

addValidator(Validator)

Parameters

validator

the new validator to be added

Adds a new validator for the field's value. All validators added to a field are checked each time the its value changes.

attach()

See Also
attach()

constructField(Class)

Parameters

propertyType

Type of the property, that needs to be edited.

Create abstract field by the type of the property.

This returns most suitable field type for editing property of given type

finalize()

Free used resources.

focus()

Ask the terminal to place the cursor to this field.

getErrorMessage()

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.

getFocusableId()

getPropertyDataSource()

Parameters

return

The current data source as a Property, or null if none defined.

Gets the current data source of the field, if any.

getTabIndex()

Parameters

return

Tab index of this field. Negative value means unspecified.

Get the tab index of this field. The tab index property is used to specify the natural tab ordering of fields.

getValidators()

Parameters

return

Unmodifiable collection that holds all validators for the field.

Gets the validators of the field.

getValue()

Parameters

return

the current value of the field

Gets the current value of the field. This is the visible, modified and possible invalid value the user have entered to the field. In the read-through mode, the abstract buffer is also updated and validation is performed.

isInvalidAllowed()

Parameters

return

true iff the invalid values are allowed.

Fields allow invalid values by default. In most cases this is wanted, because the field otherwise visually forget the user input immediately.

isReadOnly()

The abstract field is read only also if the data source is in readonly mode.

isRequired()

Parameters

return

true if the

Is this field required. Required fields must filled by the user.

isValid()

Parameters

return

true if all registered validators claim that the current value is valid, false otherwise

Tests the current value against all registered validators.

removeListener(Property.ReadOnlyStatusChangeListener)

Parameters

listener

listener to be removed

Description copied from interface: removeListener

Remove a previously registered read-only status change listener.

removeValidator(Validator)

Parameters

validator

the validator to remove

Removes a validator from the field.

setInvalidAllowed(boolean)

Fields allow invalid values by default. In most cases this is wanted, because the field otherwise visually forget the user input immediately. 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.

setPropertyDataSource(Property)

Parameters

newDataSource

the new data source Property

Sets the specified Property as the data source for the field. All uncommitted changes to the field are discarded and the value is refreshed 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.

setReadOnly(boolean)

Change the readonly state and throw read-only status change events.

setRequired(boolean)

Parameters

required

Is the field required

Set the field required. Required fields must filled by the user.

setTabIndex(int)

Parameters

tabIndex

The tab order of this component. Negative value means unspecified.

Get the tab index of this field. The tab index property is used to specify the natural tab ordering of fields.

setValue(Object)

Parameters

newValue

New value of the field.

Set the value of the field.

toString()

Parameters

return

String representation of the value stored in the Property

Returns the value of the Property in human readable textual format.

valueChange(Property.ValueChangeEvent)

Parameters

event

the value change event telling the data source contents have changed

This method listens to data source value changes and passes the changes forwards.