Class CollaborationBinder<BEAN>
- Type Parameters:
BEAN- the bean type
- All Implemented Interfaces:
HasExpirationTimeout,Serializable
Binder for creating collaborative forms with
CollaborationEngine. In addition to Binder's data binding mechanism,
CollaborationBinder synchronizes the field values between clients which are
connected to the same topic via TopicConnection.- Since:
- 1.0
- Author:
- Vaadin Ltd
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static classNested classes/interfaces inherited from class com.vaadin.flow.data.binder.Binder
com.vaadin.flow.data.binder.Binder.Binding<BEAN extends Object,TARGET extends Object>, com.vaadin.flow.data.binder.Binder.BindingBuilder<BEAN extends Object, TARGET extends Object>, com.vaadin.flow.data.binder.Binder.BindingBuilderImpl<BEAN extends Object, FIELDVALUE extends Object, TARGET extends Object>, com.vaadin.flow.data.binder.Binder.BindingImpl<BEAN extends Object, FIELDVALUE extends Object, TARGET extends Object> -
Constructor Summary
ConstructorsConstructorDescriptionCollaborationBinder(Class<BEAN> beanType, UserInfo localUser) Creates a new collaboration binder. -
Method Summary
Modifier and TypeMethodDescription<FIELDVALUE>
com.vaadin.flow.data.binder.Binder.Binding<BEAN,FIELDVALUE> bind(com.vaadin.flow.component.HasValue<?, FIELDVALUE> field, com.vaadin.flow.function.ValueProvider<BEAN, FIELDVALUE> getter, com.vaadin.flow.data.binder.Setter<BEAN, FIELDVALUE> setter) Deprecated.The method does not work with the collaboration binder.<FIELDVALUE>
com.vaadin.flow.data.binder.Binder.Binding<BEAN,FIELDVALUE> Binds the given field to the property with the given name, as described inBinder.bind(HasValue, String).voidbindInstanceFields(Object objectWithMemberFields) Binds the member fields found in the given object, as described inBinder.bindInstanceFields(Object).protected com.vaadin.flow.data.binder.Binder.BindingBuilder<BEAN,?> configureBinding(com.vaadin.flow.data.binder.Binder.BindingBuilder<BEAN, ?> baseBinding, com.vaadin.flow.data.binder.PropertyDefinition<BEAN, ?> definition) protected <FIELDVALUE,TARGET>
com.vaadin.flow.data.binder.Binder.BindingBuilder<BEAN,TARGET> doCreateBinding(com.vaadin.flow.component.HasValue<?, FIELDVALUE> field, com.vaadin.flow.data.converter.Converter<FIELDVALUE, TARGET> converter, com.vaadin.flow.data.binder.BindingValidationStatusHandler handler) <FIELDVALUE>
com.vaadin.flow.data.binder.Binder.BindingBuilder<BEAN,FIELDVALUE> forField(com.vaadin.flow.component.HasValue<?, FIELDVALUE> field) <FIELDVALUE extends Collection<ELEMENT>,ELEMENT>
com.vaadin.flow.data.binder.Binder.BindingBuilder<BEAN,FIELDVALUE> forField(com.vaadin.flow.component.HasValue<?, FIELDVALUE> field, Class<? super FIELDVALUE> collectionType, Class<ELEMENT> elementType) Creates a new binding for the given (multi select) field whose value type is a collection.<FIELDVALUE>
com.vaadin.flow.data.binder.Binder.BindingBuilder<BEAN,FIELDVALUE> Creates a new binding for the given field and type.<FIELDVALUE>
com.vaadin.flow.data.binder.Binder.BindingBuilder<BEAN,FIELDVALUE> forMemberField(com.vaadin.flow.component.HasValue<?, FIELDVALUE> field) <FIELDVALUE extends Collection<ELEMENT>,ELEMENT>
com.vaadin.flow.data.binder.Binder.BindingBuilder<BEAN,FIELDVALUE> forMemberField(com.vaadin.flow.component.HasValue<?, FIELDVALUE> field, Class<? super FIELDVALUE> collectionType, Class<ELEMENT> elementType) Creates a new binding for the given (multi select) field whose value type is a collection.<FIELDVALUE>
com.vaadin.flow.data.binder.Binder.BindingBuilder<BEAN,FIELDVALUE> forMemberField(com.vaadin.flow.component.HasValue<?, FIELDVALUE> field, Class<FIELDVALUE> fieldType) Creates a new binding for the given field and type.getBean()Deprecated.This operation, along withsetBean(Object), is not supported by the collaboration binder.Gets the optional expiration timeout of this binder.voidDeprecated.This operation is not supported by the collaboration binder.protected voidremoveBindingInternal(com.vaadin.flow.data.binder.Binder.Binding<BEAN, ?> binding) voidResets collaborative fields with values from the bound properties of the given bean.voidDeprecated.This operation is not supported by the collaboration binder.voidsetExpirationTimeout(Duration expirationTimeout) Sets the expiration timeout of this binder.<T> voidsetSerializer(Class<T> type, com.vaadin.flow.function.SerializableFunction<T, String> serializer, com.vaadin.flow.function.SerializableFunction<String, T> deserializer) Sets a custom serializer and deserializer to use for a specific value type.voidSets the topic to use with this binder and initializes the topic contents if not already set.Methods inherited from class com.vaadin.flow.data.binder.Binder
addListener, addStatusChangeListener, addValueChangeListener, bindReadOnly, bindReadOnly, clearError, createBinding, getBeanState, getBinding, getBindingExceptionHandler, getBindings, getChangedBindings, getConverterFactory, getFields, getStatusLabel, getValidationErrorHandler, getValidationStatusHandler, handleBinderValidationStatus, handleError, handleFieldValueChange, handleValidationStatus, hasChanges, hasChanges, isChangeDetectionEnabled, isDefaultValidatorsEnabled, isFieldsValidationStatusChangeListenerEnabled, isValid, isValidatorsDisabled, readRecord, refreshFields, removeBean, removeBinding, removeBinding, removeBinding, restoreBeanState, setBindingExceptionHandler, setChangeDetectionEnabled, setDefaultValidatorsEnabled, setFieldsValidationStatusChangeListenerEnabled, setReadOnly, setStatusLabel, setValidationErrorHandler, setValidationStatusHandler, setValidatorsDisabled, validate, validate, withPropertySet, withValidator, withValidator, withValidator, writeBean, writeBean, writeBeanAsDraft, writeBeanAsDraft, writeBeanIfValid, writeChangedBindingsToBean, writeRecord
-
Constructor Details
-
CollaborationBinder
Creates a new collaboration binder. It uses reflection based on the provided bean type to resolve bean properties.The provided user information is used in the field editing indicators. The name of the user will be displayed to other users when editing a field, and the user's color index will be used to set the field's highlight color.
- Parameters:
beanType- the bean type to use, notnulllocalUser- the information of the local user, notnull- Since:
- 1.0
-
-
Method Details
-
configureBinding
protected com.vaadin.flow.data.binder.Binder.BindingBuilder<BEAN,?> configureBinding(com.vaadin.flow.data.binder.Binder.BindingBuilder<BEAN, ?> baseBinding, com.vaadin.flow.data.binder.PropertyDefinition<BEAN, ?> definition) - Overrides:
configureBindingin classcom.vaadin.flow.data.binder.Binder<BEAN>
-
removeBindingInternal
- Overrides:
removeBindingInternalin classcom.vaadin.flow.data.binder.Binder<BEAN>
-
doCreateBinding
protected <FIELDVALUE,TARGET> com.vaadin.flow.data.binder.Binder.BindingBuilder<BEAN,TARGET> doCreateBinding(com.vaadin.flow.component.HasValue<?, FIELDVALUE> field, com.vaadin.flow.data.converter.Converter<FIELDVALUE, TARGET> converter, com.vaadin.flow.data.binder.BindingValidationStatusHandler handler) - Overrides:
doCreateBindingin classcom.vaadin.flow.data.binder.Binder<BEAN>
-
bind
@Deprecated public <FIELDVALUE> com.vaadin.flow.data.binder.Binder.Binding<BEAN,FIELDVALUE> bind(com.vaadin.flow.component.HasValue<?, FIELDVALUE> field, com.vaadin.flow.function.ValueProvider<BEAN, FIELDVALUE> getter, com.vaadin.flow.data.binder.Setter<BEAN, FIELDVALUE> setter) Deprecated.The method does not work with the collaboration binder. Usebind(HasValue, String)instead.Not supported by the collaboration binder! It requires a property name for binding, so the other overloadbind(HasValue, String)should be used instead.See
Binder.bind(HasValue, ValueProvider, Setter)to learn how to use the method with the regular (non-collaboration) binder.- Overrides:
bindin classcom.vaadin.flow.data.binder.Binder<BEAN>- Type Parameters:
FIELDVALUE- the value type of the field- Parameters:
field- the field to bind, notnullgetter- the function to get the value of the property to the field, notnullsetter- the function to write the field value to the property ornullif read-only- Returns:
- the newly created binding
- Throws:
UnsupportedOperationException- as the method is not supported by the collaboration binder
-
bind
public <FIELDVALUE> com.vaadin.flow.data.binder.Binder.Binding<BEAN,FIELDVALUE> bind(com.vaadin.flow.component.HasValue<?, FIELDVALUE> field, String propertyName) Binds the given field to the property with the given name, as described inBinder.bind(HasValue, String).In addition, synchronizes the values with other collaboration binder instances which are connected to the same topic.
- Overrides:
bindin classcom.vaadin.flow.data.binder.Binder<BEAN>- Type Parameters:
FIELDVALUE- the value type of the field to bind- Parameters:
field- the field to bind, notnullpropertyName- the name of the property to bind, notnull- Returns:
- the newly created binding
- Throws:
IllegalArgumentException- if the property name is invalidIllegalArgumentException- if the property has no accessible getter
-
bindInstanceFields
Binds the member fields found in the given object, as described inBinder.bindInstanceFields(Object).In addition, synchronizes the values with other collaboration binder instances which are connected to the same topic.
- Overrides:
bindInstanceFieldsin classcom.vaadin.flow.data.binder.Binder<BEAN>- Parameters:
objectWithMemberFields- the object that contains (Java) member fields to bind- Throws:
IllegalStateException- if there are incompatible HasValue<T> and property types
-
setBean
Deprecated.This operation is not supported by the collaboration binder. You can instead provide the bean for populating the fields usingsetTopic(java.lang.String, com.vaadin.flow.function.SerializableSupplier<BEAN>), and write the values back to the bean usingBinder.writeBean(BEAN).- Overrides:
setBeanin classcom.vaadin.flow.data.binder.Binder<BEAN>
-
getBean
Deprecated.This operation, along withsetBean(Object), is not supported by the collaboration binder. Instead ofsetBean(Object), you can provide the bean for populating the fields usingsetTopic(java.lang.String, com.vaadin.flow.function.SerializableSupplier<BEAN>), and write the values back to the bean usingBinder.writeBean(BEAN).- Overrides:
getBeanin classcom.vaadin.flow.data.binder.Binder<BEAN>
-
readBean
Deprecated.This operation is not supported by the collaboration binder. You can instead provide the bean for populating the fields usingsetTopic(java.lang.String, com.vaadin.flow.function.SerializableSupplier<BEAN>)to avoid overriding currently edited values. If you explicitly want to reset the field values for every user currently editing the fields, you can usereset(BEAN).- Overrides:
readBeanin classcom.vaadin.flow.data.binder.Binder<BEAN>
-
reset
Resets collaborative fields with values from the bound properties of the given bean. The values will be propagated to all collaborating users.- Parameters:
bean- the bean whose property values to read ornullto clear bound fields- Since:
- 1.0
-
setTopic
public void setTopic(String topicId, com.vaadin.flow.function.SerializableSupplier<BEAN> initialBeanSupplier) Sets the topic to use with this binder and initializes the topic contents if not already set. Setting a topic removes the connection to the previous topic (if any) and resets all bindings based on values in the new topic. The bean supplier is used to provide initial values for bindings in case the topic doesn't yet contain any values.- Parameters:
topicId- the topic id to use, ornullto not use any topicinitialBeanSupplier- a supplier that is invoked to get a bean from which to read initial values. Only invoked if there are no property values in the topic, or if the topic id isnull.- Since:
- 1.0
-
forField
public <FIELDVALUE> com.vaadin.flow.data.binder.Binder.BindingBuilder<BEAN,FIELDVALUE> forField(com.vaadin.flow.component.HasValue<?, FIELDVALUE> field) The field value will be sent over the network to synchronize the value with other users also editing the same field. The value type to use for deserializing the value is automatically determined based on the bean property type. The type must be defined separately using another overload of this method in case a converter is used or if the property type is parameterized.
- Overrides:
forFieldin classcom.vaadin.flow.data.binder.Binder<BEAN>- See Also:
-
forField
public <FIELDVALUE> com.vaadin.flow.data.binder.Binder.BindingBuilder<BEAN,FIELDVALUE> forField(com.vaadin.flow.component.HasValue<?, FIELDVALUE> field, Class<FIELDVALUE> fieldType) Creates a new binding for the given field and type. The returned builder may be further configured before invokingBinder.BindingBuilder.bind(String)which completes the binding. UntilBinding.bindis called, the binding has no effect.The field value will be sent over the network to synchronize the value with other users also editing the same field. This method allows explicitly defining the type to use. This is necessary when a converter is used since it's then not possible to derive the type from the bean property.
- Type Parameters:
FIELDVALUE- the value type of the field- Parameters:
field- the field to be bound, notnullfieldType- the type of the field value, notnull- Returns:
- the new binding builder
- See Also:
-
forField
public <FIELDVALUE extends Collection<ELEMENT>,ELEMENT> com.vaadin.flow.data.binder.Binder.BindingBuilder<BEAN,FIELDVALUE> forField(com.vaadin.flow.component.HasValue<?, FIELDVALUE> field, Class<? super FIELDVALUE> collectionType, Class<ELEMENT> elementType) Creates a new binding for the given (multi select) field whose value type is a collection. The returned builder may be further configured before invokingBinder.BindingBuilder.bind(String)which completes the binding. UntilBinding.bindis called, the binding has no effect.The field value will be sent over the network to synchronize the value with other users also editing the same field. This method allows explicitly defining the collection type and element type to use.
- Type Parameters:
FIELDVALUE- the base type of the collection, e.g.SetforCheckboxGroup<String>ELEMENT- the type of the elements in the collection, e.g.StringforCheckboxGroup<String>- Parameters:
field- the field to be bound, notnullcollectionType- the base type of the collection, e.g.Set.classforCheckboxGroup<String>, notnullelementType- the type of the elements in the collection, e.g.String.classforCheckboxGroup<String>, notnull- Returns:
- the new binding builder
- See Also:
-
forMemberField
public <FIELDVALUE> com.vaadin.flow.data.binder.Binder.BindingBuilder<BEAN,FIELDVALUE> forMemberField(com.vaadin.flow.component.HasValue<?, FIELDVALUE> field) The field value will be sent over the network to synchronize the value with other users also editing the same field. The value type to use for deserializing the value is automatically determined based on the bean property type. The type must be defined separately using another overload of this method in case a converter is used or if the property type is parameterized.
- Overrides:
forMemberFieldin classcom.vaadin.flow.data.binder.Binder<BEAN>- See Also:
-
forMemberField
public <FIELDVALUE> com.vaadin.flow.data.binder.Binder.BindingBuilder<BEAN,FIELDVALUE> forMemberField(com.vaadin.flow.component.HasValue<?, FIELDVALUE> field, Class<FIELDVALUE> fieldType) Creates a new binding for the given field and type. The returned builder may be further configured before invokingbindInstanceFields(Object). Unlike with theforField(HasValue)method, no explicit call toBinder.BindingBuilder.bind(String)is needed to complete this binding in the case that the name of the field matches a field name found in the bean.The field value will be sent over the network to synchronize the value with other users also editing the same field. This method allows explicitly defining the type to use. This is necessary when a converter is used since it's then not possible to derive the type from the bean property.
- Type Parameters:
FIELDVALUE- the value type of the field- Parameters:
field- the field to be bound, notnullfieldType-- Returns:
- the new binding builder
- Since:
- 1.0
- See Also:
-
forMemberField
public <FIELDVALUE extends Collection<ELEMENT>,ELEMENT> com.vaadin.flow.data.binder.Binder.BindingBuilder<BEAN,FIELDVALUE> forMemberField(com.vaadin.flow.component.HasValue<?, FIELDVALUE> field, Class<? super FIELDVALUE> collectionType, Class<ELEMENT> elementType) Creates a new binding for the given (multi select) field whose value type is a collection. The returned builder may be further configured before invokingbindInstanceFields(Object). Unlike with theforField(HasValue)method, no explicit call toBinder.BindingBuilder.bind(String)is needed to complete this binding in the case that the name of the field matches a field name found in the bean.The field value will be sent over the network to synchronize the value with other users also editing the same field. This method allows explicitly defining the collection type and element type to use.
- Type Parameters:
FIELDVALUE- the base type of the collection, e.g.SetforCheckboxGroup<String>ELEMENT- the type of the elements in the collection, e.g.StringforCheckboxGroup<String>- Parameters:
field- the field to be bound, notnullcollectionType- the base type of the collection, e.g.Set.classforCheckboxGroup<String>, notnullelementType- the type of the elements in the collection, e.g.String.classforCheckboxGroup<String>, notnull- Returns:
- the new binding builder
- Since:
- 1.0
- See Also:
-
setSerializer
public <T> void setSerializer(Class<T> type, com.vaadin.flow.function.SerializableFunction<T, String> serializer, com.vaadin.flow.function.SerializableFunction<String, T> deserializer) Sets a custom serializer and deserializer to use for a specific value type. The serializer and deserializer will be used for all field bindings that implicitly or explicitly use that type either as the field type or as the collection element type in case of multi select fields. It is not allowed to reconfigure the serializer and deserializer for a previously configued type nor for any of the basic types that are supported without custom logic.Field values will be sent over the network to synchronize the value with other users also editing the same field. This method allows defining callbacks to convert between the field value and the value that is sent over the network. This is necessary when using complex objects that are not suitable to be sent as-is over the network.
- Type Parameters:
T- the type handled by the serializer- Parameters:
type- the type for which to set a serializer and deserializer, notnullserializer- a callback that receives a non-empty field value and returns the value to send over the network (notnull). The callback cannot benull.deserializer- a callback that receives a value produced by the serializer callback (notnull) and returns the field value to use. The callback cannot benull.- Since:
- 1.0
-
getExpirationTimeout
Gets the optional expiration timeout of this binder. An emptyOptionalis returned if no timeout is set, which means the binder is not cleared when there are no connected users to the related topic (this is the default).- Specified by:
getExpirationTimeoutin interfaceHasExpirationTimeout- Returns:
- the expiration timeout
- Since:
- 3.1
-
setExpirationTimeout
Sets the expiration timeout of this binder. If set, this binder data is cleared whenexpirationTimeouthas passed after the last connection to the related topic is closed. If set tonull, the timeout is cancelled.- Specified by:
setExpirationTimeoutin interfaceHasExpirationTimeout- Parameters:
expirationTimeout- the expiration timeout- Since:
- 3.1
-