FieldGroup
instead of Form
for
more flexibility.@Deprecated public class Form extends AbstractField<Object> implements Item.Editor, Buffered, Item, Validatable, Action.Notifier, HasComponents, LegacyComponent
Form
is a container for fields implementing Field
interface. It provides support for any layouts and provides buffering
interface for easy connection of commit and discard buttons. All the form
fields can be customized by adding validators, setting captions and icons,
setting immediateness, etc. Also direct mechanism for replacing existing
fields with selections is given.
Form
provides customizable editor for classes implementing
Item
interface. Also the form itself implements this interface for
easier connectivity to other items. To use the form as editor for an item,
just connect the item to form with setItemDataSource(Item)
. If
only a part of the item needs to be edited,
setItemDataSource(Item,Collection)
can be used instead. After
the item has been connected to the form, the automatically created fields can
be customized and new fields can be added. If you need to connect a class
that does not implement Item
interface, most properties of any class
following bean pattern, can be accessed trough BeanItem
.
AbstractField.FocusShortcut, AbstractField.ReadOnlyStatusChangeEvent
Buffered.SourceException
Item.Editor, Item.PropertySetChangeEvent, Item.PropertySetChangeListener, Item.PropertySetChangeNotifier, Item.Viewer
HasComponents.ComponentAttachDetachNotifier, HasComponents.ComponentAttachEvent, HasComponents.ComponentAttachListener, HasComponents.ComponentDetachEvent, HasComponents.ComponentDetachListener
Component.ErrorEvent, Component.Event, Component.Focusable, Component.Listener
ClientConnector.AttachEvent, ClientConnector.AttachListener, ClientConnector.ConnectorErrorEvent, ClientConnector.DetachEvent, ClientConnector.DetachListener
Sizeable.Unit
Field.ValueChangeEvent
Property.Editor, Property.ReadOnlyException, Property.ReadOnlyStatusChangeListener, Property.ReadOnlyStatusChangeNotifier, Property.Transactional<T>, Property.ValueChangeListener, Property.ValueChangeNotifier, Property.Viewer
DESIGN_ATTR_PLAIN_TEXT
SIZE_UNDEFINED, UNITS_CM, UNITS_EM, UNITS_EX, UNITS_INCH, UNITS_MM, UNITS_PERCENTAGE, UNITS_PICAS, UNITS_PIXELS, UNITS_POINTS
Constructor and Description |
---|
Form()
Deprecated.
Constructs a new form with default layout.
|
Form(Layout formLayout)
Deprecated.
Constructs a new form with given
Layout . |
Form(Layout formLayout,
FormFieldFactory fieldFactory)
Deprecated.
Constructs a new form with given
Layout and
FormFieldFactory . |
Modifier and Type | Method and Description |
---|---|
<T extends Action & Action.Listener> |
addAction(T action)
Deprecated.
|
void |
addActionHandler(Action.Handler actionHandler)
Deprecated.
Registers a new action handler for this container
|
void |
addField(Object propertyId,
Field<?> field)
Deprecated.
Registers the field with the form and adds the field to the form layout.
|
boolean |
addItemProperty(Object id,
Property property)
Deprecated.
Adds a new property to form and create corresponding field.
|
void |
addValidator(Validator validator)
Deprecated.
Adding validators directly to form is not supported.
|
protected void |
attachField(Object propertyId,
Field field)
Deprecated.
Adds the field to the form layout.
|
protected void |
bindPropertyToField(Object propertyId,
Property property,
Field field)
Deprecated.
Binds an item property to a field.
|
void |
changeVariables(Object source,
Map<String,Object> variables)
Deprecated.
Called when one or more variables handled by the implementing class are
changed.
|
void |
clear()
Deprecated.
Clears the value of the field.
|
void |
commit()
Deprecated.
Updates all changes since the previous commit to the data source.
|
protected void |
detachField(Field field)
Deprecated.
Called when a form field is detached from a Form.
|
void |
discard()
Deprecated.
Discards all changes since last commit.
|
void |
focus()
Deprecated.
Focuses the first field in the form.
|
int |
getComponentCount()
Deprecated.
|
Iterator<Component> |
getComponentIterator()
Deprecated.
As of 7.0, use
iterator() instead. |
ErrorMessage |
getErrorMessage()
Deprecated.
The error message of a Form is the error of the first field with a
non-empty error.
|
Field |
getField(Object propertyId)
Deprecated.
Gets the field identified by the propertyid.
|
Layout |
getFooter()
Deprecated.
Returns a layout that is rendered below normal form contents.
|
FormFieldFactory |
getFormFieldFactory()
Deprecated.
Get the field factory of the form.
|
Item |
getItemDataSource()
Deprecated.
Gets the Item serving as the data source of the viewer.
|
Property |
getItemProperty(Object id)
Deprecated.
The property identified by the property id.
|
Collection<?> |
getItemPropertyIds()
Deprecated.
Gets the collection of IDs of all Properties stored in the Item.
|
Layout |
getLayout()
Deprecated.
Gets the layout of the form.
|
protected ActionManager |
getOwnActionManager()
Deprecated.
Gets the
ActionManager responsible for handling Action s
added to this Form.Note that Form has another ActionManager inherited from AbstractField . |
protected FormState |
getState()
Deprecated.
Returns the shared state bean with information to be sent from the server
to the client.
|
protected FormState |
getState(boolean markAsDirty)
Deprecated.
Returns the shared state for this connector.
|
Class<?> |
getType()
Deprecated.
Gets the field type.
|
Collection<?> |
getVisibleItemProperties()
Deprecated.
Returns the visibleProperties.
|
boolean |
isEmpty()
Deprecated.
Is the field empty?
In general, "empty" state is same as null.
|
boolean |
isInvalidAllowed()
Deprecated.
Checks the validabtable object accept invalid values.
|
boolean |
isModified()
Deprecated.
Tests if the value stored in the object has been modified since it was
last updated from the data source.
|
boolean |
isValidationVisibleOnCommit()
Deprecated.
Is validation made automatically visible on commit?
See setValidationVisibleOnCommit().
|
Iterator<Component> |
iterator()
Deprecated.
Gets an iterator to the collection of contained components.
|
void |
paintContent(PaintTarget target)
Deprecated.
Paints the Paintable into a UIDL stream.
|
<T extends Action & Action.Listener> |
removeAction(T action)
Deprecated.
|
void |
removeActionHandler(Action.Handler actionHandler)
Deprecated.
Removes a previously registered action handler for the contents of
this container.
|
void |
removeAllActionHandlers()
Deprecated.
Removes all action handlers
|
boolean |
removeAllProperties()
Deprecated.
Removes all properties and fields from the form.
|
boolean |
removeItemProperty(Object id)
Deprecated.
Removes the property and corresponding field from the form.
|
AbstractSelect |
replaceWithSelect(Object propertyId,
Object[] values,
Object[] descriptions)
Deprecated.
Sets the form field to be selectable from static list of changes.
|
void |
setBuffered(boolean buffered)
Deprecated.
Sets the buffered mode of this Field.
|
void |
setEnabled(boolean enabled)
Deprecated.
Enables or disables the component.
|
void |
setFooter(Layout footer)
Deprecated.
Sets the layout that is rendered below normal form contents.
|
protected void |
setFormDataSource(Object data,
Collection<?> properties)
Deprecated.
Updates the internal form datasource.
|
void |
setFormFieldFactory(FormFieldFactory fieldFactory)
Deprecated.
Sets the field factory used by this Form to genarate Fields for
properties.
|
void |
setImmediate(boolean immediate)
Deprecated.
Setting the form to be immediate also sets all the fields of the form to
the same state.
|
protected void |
setInternalValue(Object newValue)
Deprecated.
Sets the internal value.
|
void |
setInvalidAllowed(boolean invalidValueAllowed)
Deprecated.
Should the validabtable object accept invalid values.
|
void |
setItemDataSource(Item newDataSource)
Deprecated.
Sets the item datasource for the form.
|
void |
setItemDataSource(Item newDataSource,
Collection<?> propertyIds)
Deprecated.
Set the item datasource for the form, but limit the form contents to
specified properties of the item.
|
void |
setLayout(Layout layout)
Deprecated.
Sets the layout of the form.
|
void |
setReadOnly(boolean readOnly)
Deprecated.
Sets the component's to read-only mode to the specified state.
|
void |
setTabIndex(int tabIndex)
Deprecated.
Sets the Tabulator index of this Focusable component.
|
void |
setValidationVisibleOnCommit(boolean makeVisible)
Deprecated.
Controls the making validation visible implicitly on commit.
|
void |
setVisibleItemProperties(Collection<?> visibleProperties)
Deprecated.
Sets the visibleProperties.
|
void |
setVisibleItemProperties(Object... visibleProperties)
Deprecated.
Sets the visibleProperties.
|
void |
validate()
Deprecated.
Checks the validity of the Form and all of its fields.
|
addListener, addListener, addReadOnlyStatusChangeListener, addValueChangeListener, attach, beforeClientResponse, detach, fireReadOnlyStatusChange, fireValueChange, getConversionError, getConversionError, getConvertedValue, getConverter, getCurrentBufferedSourceException, getCustomAttributes, getInternalValue, getModelType, getPropertyDataSource, getRequiredError, getTabIndex, getValidators, getValue, isBuffered, isImmediate, isInvalidCommitted, isReadOnly, isRequired, isValid, isValidationVisible, readDesign, readOnlyStatusChange, removeAllValidators, removeListener, removeListener, removeReadOnlyStatusChangeListener, removeValidator, removeValueChangeListener, setConversionError, setConvertedValue, setConverter, setConverter, setCurrentBufferedSourceException, setInvalidCommitted, setLocale, setPropertyDataSource, setRequired, setRequiredError, setValidationVisible, setValue, setValue, setValue, shouldHideErrors, toString, validate, valueChange, writeDesign
addContextClickListener, addListener, addShortcutListener, addStyleName, findAncestor, fireComponentErrorEvent, fireComponentEvent, getActionManager, getCaption, getComponentError, getData, getDebugId, getDescription, getExplicitImmediateValue, 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, setHeight, setHeight, setHeightUndefined, setIcon, setId, setParent, setPrimaryStyleName, setResponsive, setSizeFull, setSizeUndefined, setStyleName, setStyleName, setVisible, setWidth, setWidth, setWidthUndefined
addAttachListener, 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
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
isBuffered
getValidators, isValid, removeAllValidators, removeValidator
forEach, spliterator
markAsDirty
isEnabled, isImmediate
addListener, addStyleName, attach, getCaption, getDescription, getIcon, getId, getLocale, getParent, getPrimaryStyleName, getStyleName, getUI, isEnabled, isReadOnly, isVisible, readDesign, removeListener, removeStyleName, setCaption, setIcon, setId, setParent, setPrimaryStyleName, setStyleName, setVisible, writeDesign
addAttachListener, addDetachListener, beforeClientResponse, detach, encodeState, getErrorHandler, getExtensions, getRpcManager, getStateType, handleConnectorRequest, isAttached, isConnectorEnabled, markAsDirtyRecursive, removeAttachListener, removeDetachListener, removeExtension, requestRepaint, requestRepaintAll, retrievePendingRpcCalls, setErrorHandler
getConnectorId
getHeight, getHeightUnits, getWidth, getWidthUnits, setHeight, setHeight, setHeightUndefined, setSizeFull, setSizeUndefined, setWidth, setWidth, setWidthUndefined
addShortcutListener, removeShortcutListener
public Form()
By default the form uses FormLayout
.
public Form(Layout formLayout)
Layout
.formLayout
- the layout of the form.public Form(Layout formLayout, FormFieldFactory fieldFactory)
Layout
and
FormFieldFactory
.formLayout
- the layout of the form.fieldFactory
- the FieldFactory of the form.protected FormState getState()
AbstractComponent
getState
in class AbstractField<Object>
protected FormState getState(boolean markAsDirty)
AbstractClientConnector
getState
in class AbstractField<Object>
markAsDirty
- true if the connector should automatically be marked dirty,
false otherwiseAbstractClientConnector.getState()
public void paintContent(PaintTarget target) throws PaintException
LegacyComponent
Paints the Paintable into a UIDL stream. This method creates the UIDL sequence describing it and outputs it to the given UIDL stream.
It is called when the contents of the component should be painted in response to the component first being shown or having been altered so that its visual representation is changed.
paintContent
in interface LegacyComponent
target
- the target UIDL stream where the component should paint itself
to.PaintException
- if the paint operation failed.public void changeVariables(Object source, Map<String,Object> variables)
VariableOwner
changeVariables
in interface VariableOwner
source
- the Source of the variable change. This is the origin of the
event. For example in Web Adapter this is the request.variables
- the Mapping from variable names to new variable values.public ErrorMessage getErrorMessage()
getErrorMessage
in class AbstractField<Object>
AbstractComponent.getErrorMessage()
public void setValidationVisibleOnCommit(boolean makeVisible)
makeVisible
- If true (default), validation is made visible when commit() is
called. If false, the visibility is left as it is.public boolean isValidationVisibleOnCommit()
public void commit() throws Buffered.SourceException, Validator.InvalidValueException
Buffered
commit
is called.commit
in interface Buffered
commit
in class AbstractField<Object>
Buffered.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
Buffered
discard
in interface Buffered
discard
in class AbstractField<Object>
Buffered.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()
Buffered
isModified
in interface Buffered
isModified
in class AbstractField<Object>
true
if the value in the object has been modified
since the last data source update, false
if not.public void setBuffered(boolean buffered)
AbstractField
When the field is in buffered mode, changes will not be committed to the
property data source until AbstractField.commit()
is called.
Setting buffered mode from true to false will commit any pending changes.
setBuffered
in interface Buffered
setBuffered
in class AbstractField<Object>
buffered
- true if buffered mode should be turned on, false otherwisepublic boolean addItemProperty(Object id, Property property)
addItemProperty
in interface Item
id
- ID of the new Propertyproperty
- the Property to be added and associated with the idtrue
if the operation succeeded, false
if notItem.addItemProperty(Object, Property)
public void addField(Object propertyId, Field<?> field)
The property id must not be already used in the form.
This field is added to the layout using the
attachField(Object, Field)
method.
propertyId
- the Property id the the field.field
- the field which should be added to the form.protected void attachField(Object propertyId, Field field)
The field is added to the form layout in the default position (the
position used by ComponentContainer.addComponent(Component)
. If the
underlying layout is a CustomLayout
the field is added to the
CustomLayout location given by the string representation of the property
id using CustomLayout.addComponent(Component, String)
.
Override this method to control how the fields are added to the layout.
propertyId
- field
- public Property getItemProperty(Object id)
The property data source of the field specified with property id is returned. If there is a (with specified property id) having no data source, the field is returned instead of the data source.
getItemProperty
in interface Item
id
- identifier of the Property to getnull
Item.getItemProperty(Object)
public Field getField(Object propertyId)
propertyId
- the id of the property.public Collection<?> getItemPropertyIds()
Item
getItemPropertyIds
in interface Item
public boolean removeItemProperty(Object id)
removeItemProperty
in interface Item
id
- ID of the Property to be removedtrue
if the operation succeededItem.removeItemProperty(Object)
protected void detachField(Field field)
setItemDataSource(Item)
.
Override this method to control how the fields are removed from the layout.
field
- the field to be detached from the forms layout.public boolean removeAllProperties()
true
.public Item getItemDataSource()
Item.Viewer
getItemDataSource
in interface Item.Viewer
public void setItemDataSource(Item newDataSource)
Setting item datasource clears any fields, the form might contain and adds all the properties as fields to the form.
setItemDataSource
in interface Item.Viewer
newDataSource
- The new data source ItemItem.Viewer#setItemDataSource(Item)
public void setItemDataSource(Item newDataSource, Collection<?> propertyIds)
Setting item datasource clears any fields, the form might contain and adds the specified the properties as fields to the form, in the specified order.
Item.Viewer#setItemDataSource(Item)
protected void bindPropertyToField(Object propertyId, Property property, Field field)
propertyId
- property
- field
- public Layout getLayout()
By default form uses OrderedLayout
with form
-style.
public void setLayout(Layout layout)
If set to null then Form uses a FormLayout by default.
layout
- the layout of the form.public AbstractSelect replaceWithSelect(Object propertyId, Object[] values, Object[] descriptions)
The list values and descriptions are given as array. The value-array must contain the current value of the field and the lengths of the arrays must match. Null values are not supported.
Note: since Vaadin 7.0, returns anAbstractSelect
instead of a
Select
.propertyId
- the id of the property.values
- descriptions
- public void validate() throws Validator.InvalidValueException
validate
in interface Validatable
validate
in class AbstractField<Object>
Validator.InvalidValueException
- if the value is not validValidatable.validate()
public boolean isInvalidAllowed()
isInvalidAllowed
in interface Validatable
isInvalidAllowed
in class AbstractField<Object>
Validatable.isInvalidAllowed()
public void setInvalidAllowed(boolean invalidValueAllowed) throws UnsupportedOperationException
setInvalidAllowed
in interface Validatable
setInvalidAllowed
in class AbstractField<Object>
UnsupportedOperationException
- if the setInvalidAllowed is not supported.Validatable.setInvalidAllowed(boolean)
public void setReadOnly(boolean readOnly)
setReadOnly
in interface Property<Object>
setReadOnly
in interface Component
setReadOnly
in class AbstractField<Object>
readOnly
- a boolean value specifying whether the component is put
read-only mode or notComponent.setReadOnly(boolean)
public void setFormFieldFactory(FormFieldFactory fieldFactory)
FormFieldFactory
is used to create fields for form properties.
DefaultFieldFactory
is used by default.fieldFactory
- the new factory used to create the fields.Field
,
FormFieldFactory
public FormFieldFactory getFormFieldFactory()
public Class<?> getType()
getType
in interface Property<Object>
getType
in class AbstractField<Object>
AbstractField.getType()
protected void setInternalValue(Object newValue)
setInternalValue
in class AbstractField<Object>
newValue
- the new value to be set.AbstractField.setInternalValue(java.lang.Object)
protected void setFormDataSource(Object data, Collection<?> properties)
data
- properties
- public Collection<?> getVisibleItemProperties()
public void setVisibleItemProperties(Collection<?> visibleProperties)
visibleProperties
- the visibleProperties to set.public void setVisibleItemProperties(Object... visibleProperties)
visibleProperties
- the visibleProperties to set.public void focus()
focus
in interface Component.Focusable
focus
in class AbstractField<Object>
Component.Focusable.focus()
public void setTabIndex(int tabIndex)
setTabIndex
in interface Component.Focusable
setTabIndex
in class AbstractField<Object>
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.setTabIndex(int)
public void setImmediate(boolean immediate)
setImmediate
in class AbstractComponent
immediate
- the boolean value specifying if the component should be in the
immediate mode after the call.public boolean isEmpty()
A Form is empty if all of its fields are empty.
public 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 void addValidator(Validator validator)
addValidator
in interface Validatable
addValidator
in class AbstractField<Object>
validator
- the new validator to be added.public Layout getFooter()
public void setFooter(Layout footer)
footer
- the new footer layoutpublic void setEnabled(boolean enabled)
Component
Button enabled = new Button("Enabled"); enabled.setEnabled(true); // The default layout.addComponent(enabled); Button disabled = new Button("Disabled"); disabled.setEnabled(false); layout.addComponent(disabled);
This method will trigger a RepaintRequestEvent
for the component
and, if it is a ComponentContainer
, for all its children
recursively.
setEnabled
in interface Component
setEnabled
in class AbstractComponent
enabled
- a boolean value specifying if the component should be enabled
or notprotected ActionManager getOwnActionManager()
ActionManager
responsible for handling Action
s
added to this Form.AbstractField
. The ownActionManager handles Actions attached to
this Form specifically, while the ActionManager in AbstractField
delegates to the containing Window (i.e global Actions).public void addActionHandler(Action.Handler actionHandler)
Action.Container
addActionHandler
in interface Action.Container
actionHandler
- the new handler to be added.public void removeActionHandler(Action.Handler actionHandler)
Action.Container
removeActionHandler
in interface Action.Container
actionHandler
- the handler to be removed.public void removeAllActionHandlers()
public <T extends Action & Action.Listener> void addAction(T action)
addAction
in interface Action.Notifier
public <T extends Action & Action.Listener> void removeAction(T action)
removeAction
in interface Action.Notifier
public Iterator<Component> iterator()
HasComponents
iterator
in interface HasComponents
iterator
in interface Iterable<Component>
@Deprecated public Iterator<Component> getComponentIterator()
iterator()
instead.public int getComponentCount()
Copyright © 2019 Vaadin Ltd. All rights reserved.