BEAN
- the bean typepublic class CollaborationBinder<BEAN> extends Binder<BEAN> implements HasExpirationTimeout
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
.Modifier and Type | Class and Description |
---|---|
protected static class |
CollaborationBinder.CollaborationBindingBuilderImpl<BEAN,FIELDVALUE,TARGET> |
Binder.Binding<BEAN,TARGET>, Binder.BindingBuilder<BEAN,TARGET>, Binder.BindingBuilderImpl<BEAN,FIELDVALUE,TARGET>, Binder.BindingImpl<BEAN,FIELDVALUE,TARGET>
Constructor and Description |
---|
CollaborationBinder(Class<BEAN> beanType,
UserInfo localUser)
Creates a new collaboration binder.
|
Modifier and Type | Method and Description |
---|---|
<FIELDVALUE> |
bind(HasValue<?,FIELDVALUE> field,
String propertyName)
Binds the given field to the property with the given name, as described
in
Binder.bind(HasValue, String) . |
<FIELDVALUE> |
bind(HasValue<?,FIELDVALUE> field,
ValueProvider<BEAN,FIELDVALUE> getter,
Setter<BEAN,FIELDVALUE> setter)
Deprecated.
The method does not work with the collaboration binder. Use
bind(HasValue, String) instead. |
void |
bindInstanceFields(Object objectWithMemberFields)
Binds the member fields found in the given object, as described in
Binder.bindInstanceFields(Object) . |
protected Binder.BindingBuilder<BEAN,?> |
configureBinding(Binder.BindingBuilder<BEAN,?> baseBinding,
PropertyDefinition<BEAN,?> definition)
Configures the
binding with the property definition
definition before it's being bound. |
protected <FIELDVALUE,TARGET> |
doCreateBinding(HasValue<?,FIELDVALUE> field,
Converter<FIELDVALUE,TARGET> converter,
BindingValidationStatusHandler handler) |
<FIELDVALUE> |
forField(HasValue<?,FIELDVALUE> field)
Creates a new binding for the given field.
|
<FIELDVALUE extends Collection<ELEMENT>,ELEMENT> |
forField(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> |
forField(HasValue<?,FIELDVALUE> field,
Class<FIELDVALUE> fieldType)
Creates a new binding for the given field and type.
|
<FIELDVALUE> |
forMemberField(HasValue<?,FIELDVALUE> field)
Creates a new binding for the given field.
|
<FIELDVALUE extends Collection<ELEMENT>,ELEMENT> |
forMemberField(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> |
forMemberField(HasValue<?,FIELDVALUE> field,
Class<FIELDVALUE> fieldType)
Creates a new binding for the given field and type.
|
BEAN |
getBean()
Deprecated.
This operation, along with
setBean(Object) , is not
supported by the collaboration binder. Instead of
setBean(Object) , you can provide the bean for
populating the fields using setTopic(java.lang.String, com.vaadin.flow.function.SerializableSupplier<BEAN>) , and write the
values back to the bean using Binder.writeBean(BEAN) . |
Optional<Duration> |
getExpirationTimeout()
Gets the optional expiration timeout of this binder.
|
void |
readBean(BEAN bean)
Deprecated.
This operation is not supported by the collaboration binder.
You can instead provide the bean for populating the fields
using
setTopic(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 use
reset(BEAN) . |
protected void |
removeBindingInternal(Binder.Binding<BEAN,?> binding)
Removes (internally) the
Binding from the bound properties map
(if present) and from the list of Binding s. |
void |
reset(BEAN bean)
Resets collaborative fields with values from the bound properties of the
given bean.
|
void |
setBean(BEAN bean)
Deprecated.
This operation is not supported by the collaboration binder.
You can instead provide the bean for populating the fields
using
setTopic(java.lang.String, com.vaadin.flow.function.SerializableSupplier<BEAN>) , and write the values back to the
bean using Binder.writeBean(BEAN) . |
void |
setExpirationTimeout(Duration expirationTimeout)
Sets the expiration timeout of this binder.
|
<T> void |
setSerializer(Class<T> type,
SerializableFunction<T,String> serializer,
SerializableFunction<String,T> deserializer)
Sets a custom serializer and deserializer to use for a specific value
type.
|
void |
setTopic(String topicId,
SerializableSupplier<BEAN> initialBeanSupplier)
Sets the topic to use with this binder and initializes the topic contents
if not already set.
|
addListener, addStatusChangeListener, addValueChangeListener, clearError, createBinding, getBeanState, getBinding, getBindings, getFields, getStatusLabel, getValidationStatusHandler, handleBinderValidationStatus, handleError, handleFieldValueChange, handleValidationStatus, hasChanges, isValid, isValidatorsDisabled, removeBean, removeBinding, removeBinding, removeBinding, restoreBeanState, setReadOnly, setStatusLabel, setValidationStatusHandler, setValidatorsDisabled, validate, validate, withPropertySet, withValidator, withValidator, withValidator, writeBean, writeBeanAsDraft, writeBeanAsDraft, writeBeanIfValid
public CollaborationBinder(Class<BEAN> beanType, UserInfo localUser)
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.
beanType
- the bean type to use, not null
localUser
- the information of the local user, not null
protected Binder.BindingBuilder<BEAN,?> configureBinding(Binder.BindingBuilder<BEAN,?> baseBinding, PropertyDefinition<BEAN,?> definition)
Binder
binding
with the property definition
definition
before it's being bound.configureBinding
in class Binder<BEAN>
baseBinding
- a binding to configuredefinition
- a property definition informationprotected void removeBindingInternal(Binder.Binding<BEAN,?> binding)
Binder
Binding
from the bound properties map
(if present) and from the list of Binding
s. Note that this DOES
NOT remove the ValueChangeListener
that the Binding
might
have registered with any HasValue
s or decouple the Binder
from within the Binding
. To do that, use
Binder.Binding.unbind()
This method should just be used for internal cleanup.removeBindingInternal
in class Binder<BEAN>
binding
- The Binding
to remove from the binding mapprotected <FIELDVALUE,TARGET> Binder.BindingBuilder<BEAN,TARGET> doCreateBinding(HasValue<?,FIELDVALUE> field, Converter<FIELDVALUE,TARGET> converter, BindingValidationStatusHandler handler)
doCreateBinding
in class Binder<BEAN>
@Deprecated public <FIELDVALUE> Binder.Binding<BEAN,FIELDVALUE> bind(HasValue<?,FIELDVALUE> field, ValueProvider<BEAN,FIELDVALUE> getter, Setter<BEAN,FIELDVALUE> setter)
bind(HasValue, String)
instead.bind(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.
bind
in class Binder<BEAN>
FIELDVALUE
- the value type of the fieldfield
- the field to bind, not null
getter
- the function to get the value of the property to the field,
not null
setter
- the function to write the field value to the property or
null
if read-onlyUnsupportedOperationException
- as the method is not supported by the collaboration binderpublic <FIELDVALUE> Binder.Binding<BEAN,FIELDVALUE> bind(HasValue<?,FIELDVALUE> field, String propertyName)
Binder.bind(HasValue, String)
.
In addition, synchronizes the values with other collaboration binder instances which are connected to the same topic.
bind
in class Binder<BEAN>
FIELDVALUE
- the value type of the field to bindfield
- the field to bind, not null
propertyName
- the name of the property to bind, not null
IllegalArgumentException
- if the property name is invalidIllegalArgumentException
- if the property has no accessible getterBinder.bind(HasValue, ValueProvider, Setter)
public void bindInstanceFields(Object objectWithMemberFields)
Binder.bindInstanceFields(Object)
.
In addition, synchronizes the values with other collaboration binder instances which are connected to the same topic.
bindInstanceFields
in class Binder<BEAN>
objectWithMemberFields
- the object that contains (Java) member fields to bindIllegalStateException
- if there are incompatible HasValue<T> and property
types@Deprecated public void setBean(BEAN bean)
setTopic(java.lang.String, com.vaadin.flow.function.SerializableSupplier<BEAN>)
, and write the values back to the
bean using Binder.writeBean(BEAN)
.Binder
null
value removes a currently bound bean.
When a bean is bound, the field values are updated by invoking their corresponding getter functions. Any changes to field values are reflected back to their corresponding property values of the bean as long as the bean is bound.
Any change made in the fields also runs validation for the field
Binder.Binding
and bean level validation for this binder (bean level
validators are added using Binder.withValidator(Validator)
.
After updating each field, the value is read back from the field and the bean's property value is updated if it has been changed from the original value by the field or a converter.
setBean
in class Binder<BEAN>
bean
- the bean to edit, or null
to remove a currently bound
bean and clear bound fieldsBinder.readBean(Object)
,
Binder.writeBean(Object)
,
Binder.writeBeanIfValid(Object)
@Deprecated public BEAN getBean()
setBean(Object)
, is not
supported by the collaboration binder. Instead of
setBean(Object)
, you can provide the bean for
populating the fields using setTopic(java.lang.String, com.vaadin.flow.function.SerializableSupplier<BEAN>)
, and write the
values back to the bean using Binder.writeBean(BEAN)
.Binder
Binder.bind(com.vaadin.flow.component.HasValue<?, FIELDVALUE>, com.vaadin.flow.function.ValueProvider<BEAN, FIELDVALUE>, com.vaadin.flow.data.binder.Setter<BEAN, FIELDVALUE>)
, or null if a
bean is not currently bound.@Deprecated public void readBean(BEAN bean)
setTopic(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 use
reset(BEAN)
.Binder
The bean is not otherwise associated with this binder; in particular its
property values are not bound to the field value changes. To achieve
that, use Binder.setBean(Object)
.
readBean
in class Binder<BEAN>
bean
- the bean whose property values to read or null
to
clear bound fieldsBinder.setBean(Object)
,
Binder.writeBeanIfValid(Object)
,
Binder.writeBean(Object)
public void reset(BEAN bean)
bean
- the bean whose property values to read or null
to
clear bound fieldspublic void setTopic(String topicId, SerializableSupplier<BEAN> initialBeanSupplier)
topicId
- the topic id to use, or null
to 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 is null
.public <FIELDVALUE> Binder.BindingBuilder<BEAN,FIELDVALUE> forField(HasValue<?,FIELDVALUE> field)
Binder.BindingBuilder.bind(ValueProvider, Setter)
which completes the
binding. Until Binding.bind
is called, the binding has no effect.
Note: Not all HasValue
implementations support
passing null
as the value. For these the Binder will
automatically change null
to a null representation provided by
HasValue.getEmptyValue()
. This conversion is one-way only, if you
want to have a two-way mapping back to null
, use
Binder.BindingBuilder.withNullRepresentation(Object)
.
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.
forField
in class Binder<BEAN>
FIELDVALUE
- the value type of the fieldfield
- the field to be bound, not nullforField(HasValue, Class)
,
forField(HasValue, Class, Class)
public <FIELDVALUE> Binder.BindingBuilder<BEAN,FIELDVALUE> forField(HasValue<?,FIELDVALUE> field, Class<FIELDVALUE> fieldType)
BindingBuilder#bind(String)
which completes the binding. Until
Binding.bind
is 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.
FIELDVALUE
- the value type of the fieldfield
- the field to be bound, not null
fieldType
- the type of the field value, not null
forField(HasValue)
,
forField(HasValue, Class, Class)
,
setSerializer(Class, SerializableFunction, SerializableFunction)
public <FIELDVALUE extends Collection<ELEMENT>,ELEMENT> Binder.BindingBuilder<BEAN,FIELDVALUE> forField(HasValue<?,FIELDVALUE> field, Class<? super FIELDVALUE> collectionType, Class<ELEMENT> elementType)
BindingBuilder#bind(String)
which completes the binding.
Until Binding.bind
is 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.
FIELDVALUE
- the base type of the collection, e.g. Set
for
CheckboxGroup<String>
ELEMENT
- the type of the elements in the collection, e.g.
String
for CheckboxGroup<String>
field
- the field to be bound, not null
collectionType
- the base type of the collection, e.g. Set.class
for
CheckboxGroup<String>
, not null
elementType
- the type of the elements in the collection, e.g.
String.class
for CheckboxGroup<String>
, not
null
forField(HasValue)
,
forField(HasValue, Class)
,
setSerializer(Class, SerializableFunction, SerializableFunction)
public <FIELDVALUE> Binder.BindingBuilder<BEAN,FIELDVALUE> forMemberField(HasValue<?,FIELDVALUE> field)
Binder.bindInstanceFields(Object)
.
Unlike with the Binder.forField(HasValue)
method, no explicit call to
Binder.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. 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.
forMemberField
in class Binder<BEAN>
FIELDVALUE
- the value type of the fieldfield
- the field to be bound, not nullforMemberField(HasValue, Class)
,
forMemberField(HasValue, Class, Class)
public <FIELDVALUE> Binder.BindingBuilder<BEAN,FIELDVALUE> forMemberField(HasValue<?,FIELDVALUE> field, Class<FIELDVALUE> fieldType)
bindInstanceFields(Object)
. Unlike with the
forField(HasValue)
method, no explicit call to
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.
FIELDVALUE
- the value type of the fieldfield
- the field to be bound, not null
fieldType
- forMemberField(HasValue)
,
forMemberField(HasValue, Class, Class)
,
setSerializer(Class, SerializableFunction, SerializableFunction)
public <FIELDVALUE extends Collection<ELEMENT>,ELEMENT> Binder.BindingBuilder<BEAN,FIELDVALUE> forMemberField(HasValue<?,FIELDVALUE> field, Class<? super FIELDVALUE> collectionType, Class<ELEMENT> elementType)
bindInstanceFields(Object)
. Unlike with the
forField(HasValue)
method, no explicit call to
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.
FIELDVALUE
- the base type of the collection, e.g. Set
for
CheckboxGroup<String>
ELEMENT
- the type of the elements in the collection, e.g.
String
for CheckboxGroup<String>
field
- the field to be bound, not null
collectionType
- the base type of the collection, e.g. Set.class
for
CheckboxGroup<String>
, not null
elementType
- the type of the elements in the collection, e.g.
String.class
for CheckboxGroup<String>
, not
null
forMemberField(HasValue)
,
forMemberField(HasValue, Class)
,
setSerializer(Class, SerializableFunction, SerializableFunction)
public <T> void setSerializer(Class<T> type, SerializableFunction<T,String> serializer, SerializableFunction<String,T> deserializer)
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.
T
- the type handled by the serializertype
- the type for which to set a serializer and deserializer, not
null
serializer
- a callback that receives a non-empty field value and returns
the value to send over the network (not null
).
The callback cannot be null
.deserializer
- a callback that receives a value produced by the serializer
callback (not null
) and returns the field value
to use. The callback cannot be null
.public Optional<Duration> getExpirationTimeout()
Optional
is 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).getExpirationTimeout
in interface HasExpirationTimeout
public void setExpirationTimeout(Duration expirationTimeout)
expirationTimeout
has passed after the last
connection to the related topic is closed. If set to null
, the
timeout is cancelled.setExpirationTimeout
in interface HasExpirationTimeout
expirationTimeout
- the expiration timeoutCopyright © 2021. All rights reserved.