com.vaadin.flow.server.webcomponent.
Class WebComponentBinding<C extends Component>
- java.lang.Object
-
- com.vaadin.flow.server.webcomponent.WebComponentBinding<C>
-
Type Parameters:
C
- type of the exported componentAll Implemented Interfaces:
public final class WebComponentBinding<C extends Component> extends Object implements Serializable
Represents a single instance of a exported web component instance embedded onto a host page. Contains a unique
Component
instance and property value hosts tied to the specific web component instance. Facilitates property updates from the client to thecomponent
.Since:
2.0
Author:
Vaadin Ltd.
See Also:
-
-
Constructor Summary
Constructors Constructor Description WebComponentBinding(C component)
Constructs a new
WebComponentBinding
.
-
Method Summary
All Methods Modifier and Type Method Description void
bindProperty(PropertyConfigurationImpl<C,? extends Serializable> propertyConfiguration, boolean overrideDefault, elemental.json.JsonValue startingValue)
Adds a property to
this
web component binding based on thepropertyConfiguration
.C
getComponent()
Retrieves the bound
Component
instance.Class<? extends Serializable>
getPropertyType(String propertyName)
Retrieve the type of a property's value.
boolean
hasProperty(String propertyName)
Does the component binding have a property identified by given name.
void
updatePropertiesToComponent()
Calls the bound change handlers defined via
PropertyConfiguration.onChange(SerializableBiConsumer)
for each bound property with the current value of the property.void
updateProperty(String propertyName, elemental.json.JsonValue jsonValue)
Updates a property bound to the
component
.void
updateProperty(String propertyName, Serializable value)
Updates a property bound to the
component
.
-
-
-
Constructor Detail
-
WebComponentBinding
public WebComponentBinding(C component)
Constructs a new
WebComponentBinding
. The boundComponent
is given viacomponent
parameter. The web component properties are bound by callingbindProperty(PropertyConfigurationImpl, boolean, elemental.json.JsonValue)
;Parameters:
component
- component which exposesproperties
as web component. Notnull
Throws:
NullPointerException
- ifcomponent
isnull
-
-
Method Detail
-
updateProperty
public void updateProperty(String propertyName, Serializable value)
Updates a property bound to the
component
. If the property has an attached listener, thevalue
is also delivered to the listener. If thevalue
isnull
, the property is set to its default value (which could benull
).Parameters:
propertyName
- name of the property, notnull
value
- new value to set for the propertyThrows:
NullPointerException
- ifpropertyName
isnull
IllegalArgumentException
- if no bound property can be found forpropertyName
-
updateProperty
public void updateProperty(String propertyName, elemental.json.JsonValue jsonValue)
Updates a property bound to the
component
. Converts thejsonValue
into the correct type if able and then callsupdateProperty(String, java.io.Serializable)
.Parameters:
propertyName
- name of the property, notnull
jsonValue
- new value to set for the propertyThrows:
NullPointerException
- ifpropertyName
isnull
IllegalArgumentException
- if no bound property can be found forpropertyName
IllegalArgumentException
- if thejsonValue
cannot be converted to the type of the property identified bypropertyName
.
-
getComponent
public C getComponent()
Retrieves the bound
Component
instance.Returns:
component
instance
-
getPropertyType
public Class<? extends Serializable> getPropertyType(String propertyName)
Retrieve the type of a property's value.
Parameters:
propertyName
- name of the propertyReturns:
property type
-
hasProperty
public boolean hasProperty(String propertyName)
Does the component binding have a property identified by given name.
Parameters:
propertyName
- name of the propertyReturns:
has property
-
updatePropertiesToComponent
public void updatePropertiesToComponent()
Calls the bound change handlers defined via
PropertyConfiguration.onChange(SerializableBiConsumer)
for each bound property with the current value of the property.
-
bindProperty
public void bindProperty(PropertyConfigurationImpl<C,? extends Serializable> propertyConfiguration, boolean overrideDefault, elemental.json.JsonValue startingValue)
Adds a property to
this
web component binding based on thepropertyConfiguration
. If a property with an existing name is bound, the previous binding is removed.Parameters:
propertyConfiguration
- property configuration, notnull
overrideDefault
- set totrue
if the property should be initialized withstartingValue
instead of default value found inPropertyData
startingValue
- starting value for the property. Can benull
.overrideDefault
must betrue
for this value to have any effectThrows:
NullPointerException
- ifpropertyConfiguration
isnull
-
-