Class WebComponent<C extends Component>
- java.lang.Object
-
- com.vaadin.flow.component.webcomponent.WebComponent<C>
-
- Type Parameters:
C- type of thecomponentexported as web component
- All Implemented Interfaces:
Serializable
public final class WebComponent<C extends Component> extends Object implements Serializable
Acts as a proxy to the web component root onto which the exporterComponentis added. Allows updating web component properties and firing custom events on the client-side.- Since:
- 2.0
- Author:
- Vaadin Ltd.
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description WebComponent(WebComponentBinding binding, Element componentHost)Constructs aWebComponent.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidfireEvent(String eventName)Fires a custom event on the client-side originating from the web component.voidfireEvent(String eventName, elemental.json.JsonValue objectData)Fires a custom event on the client-side originating from the web component with custom event data.voidfireEvent(String eventName, elemental.json.JsonValue objectData, EventOptions options)Fires a custom event on the client-side originating from the web component with custom event data.<P extends Serializable>
voidsetProperty(PropertyConfiguration<C,P> propertyConfiguration, P value)Sets property value on the client-side to the givenvalue.
-
-
-
Constructor Detail
-
WebComponent
public WebComponent(WebComponentBinding binding, Element componentHost)
Constructs aWebComponent.WebComponentBindingprovides the instance of theComponentexported as a web component.Bindingalso defines the properties the web component has.Elementis the host element which contains the exportedcomponentinstance (provided by thebinding).- Parameters:
binding- binds web component configuration tocomponent XcomponentHost- hostcomponent Xon the embedding page- See Also:
for the web component host
-
-
Method Detail
-
fireEvent
public void fireEvent(String eventName)
Fires a custom event on the client-side originating from the web component. This event does not bubble in the DOM hierarchy.- Parameters:
eventName- name of the event, not null- See Also:
for full set of options
-
fireEvent
public void fireEvent(String eventName, elemental.json.JsonValue objectData)
Fires a custom event on the client-side originating from the web component with custom event data. This event does not bubble in the DOM hierarchy.- Parameters:
eventName- name of the event, not nullobjectData- data the event should carry. This data is placed as thedetailproperty of the event, nullable- See Also:
for full set of options
-
fireEvent
public void fireEvent(String eventName, elemental.json.JsonValue objectData, EventOptions options)
Fires a custom event on the client-side originating from the web component with custom event data. Allows modifying the default event behavior withEventOptions.- Parameters:
eventName- name of the event, not nullobjectData- data the event should carry. This data is placed as thedetailproperty of the event, nullableoptions- event options forbubbles,cancelable, andcomposedflags, not null- Throws:
NullPointerException- if eithereventNameoroptionsisnull
-
setProperty
public <P extends Serializable> void setProperty(PropertyConfiguration<C,P> propertyConfiguration, P value)
Sets property value on the client-side to the givenvalue. The requiredPropertyConfigurationImplis received fromWebComponentExporterwhen a new property is added for the web component.- Type Parameters:
P- type of the property value being set. If the type does not match the original property type, throws an exception- Parameters:
propertyConfiguration- identifies the property for which the value is being set, notnullvalue- new value for the property, can benull- Throws:
NullPointerException- ifpropertyConfigurationisnullIllegalArgumentException- ifPropertyConfigurationis not a correct implementationIllegalArgumentException- if the web component does not have a property identified bypropertyConfigurationIllegalArgumentException- the providedvalueis not of the type expected by the property
-
-