Class BeanFieldGroup<T>
- java.lang.Object
-
- com.vaadin.data.fieldgroup.FieldGroup
-
- com.vaadin.data.fieldgroup.BeanFieldGroup<T>
-
- All Implemented Interfaces:
Serializable
public class BeanFieldGroup<T> extends FieldGroup
- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class com.vaadin.data.fieldgroup.FieldGroup
FieldGroup.BindException, FieldGroup.CommitEvent, FieldGroup.CommitException, FieldGroup.CommitHandler, FieldGroup.FieldGroupInvalidValueException, FieldGroup.SearchException
-
-
Constructor Summary
Constructors Constructor Description BeanFieldGroup(Class<T> beanType)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
bind(Field field, Object propertyId)
Binds the field with the given propertyId from the current item.static <T> BeanFieldGroup<T>
bindFieldsBuffered(T bean, Object objectWithMemberFields)
Convenience method to bind Fields from a given "field container" to a given bean with buffering enabled.static <T> BeanFieldGroup<T>
bindFieldsUnbuffered(T bean, Object objectWithMemberFields)
Convenience method to bind Fields from a given "field container" to a given bean with buffering disabled.<T extends Field>
TbuildAndBind(String caption, Object propertyId, Class<T> fieldType)
Builds a field using the given caption and binds it to the given property id using the field binder.protected void
configureField(Field<?> field)
Configures a field with the settings set for this FieldBinder.protected Object
findPropertyId(Field memberField)
Searches for a property id from the current itemDataSource that matches the given memberField.BeanItem<T>
getItemDataSource()
Gets the item used by this FieldBinder.protected Class<?>
getPropertyType(Object propertyId)
Gets the type of the property with the given property id.protected static boolean
isBeanValidationImplementationAvailable()
Checks whether a bean validation implementation (e.g.void
setItemDataSource(Item item)
Updates the item that is used by this FieldBinder.void
setItemDataSource(T bean)
Helper method for setting the data source directly using a bean.void
unbind(Field<?> field)
Detaches the field from its property id and removes it from this FieldBinder.-
Methods inherited from class com.vaadin.data.fieldgroup.FieldGroup
addCommitHandler, bindFields, bindMemberFields, build, buildAndBind, buildAndBind, buildAndBindMemberFields, buildAndBindMemberFields, clear, clearField, commit, discard, getBoundPropertyIds, getCommitHandlers, getField, getFieldFactory, getFields, getFieldsInDeclareOrder, getItemProperty, getPropertyId, getUnboundPropertyIds, isBuffered, isEnabled, isModified, isReadOnly, isValid, minifyFieldName, removeCommitHandler, setBuffered, setEnabled, setFieldFactory, setReadOnly, wrapInTransactionalProperty
-
-
-
-
Method Detail
-
getPropertyType
protected Class<?> getPropertyType(Object propertyId)
Description copied from class:FieldGroup
Gets the type of the property with the given property id.- Overrides:
getPropertyType
in classFieldGroup
- Parameters:
propertyId
- The propertyId. Must be find- Returns:
- The type of the property
-
findPropertyId
protected Object findPropertyId(Field memberField)
Description copied from class:FieldGroup
Searches for a property id from the current itemDataSource that matches the given memberField.If perfect match is not found, uses a case insensitive search that also ignores underscores. Returns null if no match is found. Throws a SearchException if no item data source has been set.
The propertyId search logic used by
buildAndBindMemberFields
can easily be customized by overriding this method. No other changes are needed.- Overrides:
findPropertyId
in classFieldGroup
- Parameters:
memberField
- The field an object id is searched for- Returns:
-
setItemDataSource
public void setItemDataSource(T bean)
Helper method for setting the data source directly using a bean. This method wraps the bean in aBeanItem
and callssetItemDataSource(Item)
.For null values, a null item is passed to
setItemDataSource(Item)
to be properly clear fields.- Parameters:
bean
- The bean to use as data source.
-
setItemDataSource
public void setItemDataSource(Item item)
Description copied from class:FieldGroup
Updates the item that is used by this FieldBinder. Rebinds all fields to the properties in the new item.- Overrides:
setItemDataSource
in classFieldGroup
- Parameters:
item
- The new item to use
-
getItemDataSource
public BeanItem<T> getItemDataSource()
Description copied from class:FieldGroup
Gets the item used by this FieldBinder. Note that you must callFieldGroup.commit()
for the item to be updated unless buffered mode has been switched off.- Overrides:
getItemDataSource
in classFieldGroup
- Returns:
- The item used by this FieldBinder
- See Also:
FieldGroup.setBuffered(boolean)
,FieldGroup.commit()
-
bind
public void bind(Field field, Object propertyId)
Description copied from class:FieldGroup
Binds the field with the given propertyId from the current item. If an item has not been set then the binding is postponed until the item is set usingFieldGroup.setItemDataSource(Item)
.This method also adds validators when applicable.
- Overrides:
bind
in classFieldGroup
- Parameters:
field
- The field to bindpropertyId
- The propertyId to bind to the field
-
buildAndBind
public <T extends Field> T buildAndBind(String caption, Object propertyId, Class<T> fieldType) throws FieldGroup.BindException
Description copied from class:FieldGroup
Builds a field using the given caption and binds it to the given property id using the field binder. Ensures the new field is of the given type.- Overrides:
buildAndBind
in classFieldGroup
- Parameters:
caption
- The caption for the fieldpropertyId
- The property id to bind to. Must be present in the field finder.- Returns:
- The created and bound field. Can be any type of
Field
. - Throws:
FieldGroup.BindException
- If the field could not be created
-
unbind
public void unbind(Field<?> field) throws FieldGroup.BindException
Description copied from class:FieldGroup
Detaches the field from its property id and removes it from this FieldBinder.Note that the field is not detached from its property data source if it is no longer connected to the same property id it was bound to using this FieldBinder.
- Overrides:
unbind
in classFieldGroup
- Parameters:
field
- The field to detach- Throws:
FieldGroup.BindException
- If the field is not bound by this field binder or not bound to the correct property id
-
configureField
protected void configureField(Field<?> field)
Description copied from class:FieldGroup
Configures a field with the settings set for this FieldBinder.By default this updates the buffered, read only and enabled state of the field. Also adds validators when applicable. Fields with read only data source are always configured as read only.
- Overrides:
configureField
in classFieldGroup
- Parameters:
field
- The field to update
-
isBeanValidationImplementationAvailable
protected static boolean isBeanValidationImplementationAvailable()
Checks whether a bean validation implementation (e.g. Hibernate Validator or Apache Bean Validation) is available. TODO move this method to some more generic location- Returns:
- true if a JSR-303 bean validation implementation is available
-
bindFieldsUnbuffered
public static <T> BeanFieldGroup<T> bindFieldsUnbuffered(T bean, Object objectWithMemberFields)
Convenience method to bind Fields from a given "field container" to a given bean with buffering disabled.The returned
BeanFieldGroup
can be used for further configuration.- Parameters:
bean
- the bean to be boundobjectWithMemberFields
- the class that containsField
s for bean properties- Returns:
- the bean field group used to make binding
- Since:
- 7.2
- See Also:
bindFieldsBuffered(Object, Object)
,FieldGroup.bindMemberFields(Object)
-
bindFieldsBuffered
public static <T> BeanFieldGroup<T> bindFieldsBuffered(T bean, Object objectWithMemberFields)
Convenience method to bind Fields from a given "field container" to a given bean with buffering enabled.The returned
BeanFieldGroup
can be used for further configuration.- Parameters:
bean
- the bean to be boundobjectWithMemberFields
- the class that containsField
s for bean properties- Returns:
- the bean field group used to make binding
- Since:
- 7.2
- See Also:
bindFieldsUnbuffered(Object, Object)
,FieldGroup.bindMemberFields(Object)
-
-