com.vaadin.flow.data.renderer.
Class ComponentRenderer<COMPONENT extends Component,SOURCE>
Type Parameters:
COMPONENT
- the type of the output component
SOURCE
- the type of the input model object
All Implemented Interfaces:
Direct Known Subclasses:
BasicRenderer
, HierarchyColumnComponentRenderer
, IconRenderer
Base class for all renderers that support arbitrary Component
s.
Components that support renderers should use the appropriate method from this
class to provide component rendering: Renderer.render(Element, DataKeyMapper)
for components that uses <template>
, and
createComponent(Object)
for components that use light-dom.
Author:
Vaadin Ltd
See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionComponentRenderer
(SerializableFunction<SOURCE, COMPONENT> componentFunction) Creates a new ComponentRenderer that uses the componentFunction to generate new
Component
instances.ComponentRenderer
(SerializableFunction<SOURCE, COMPONENT> componentFunction, SerializableBiFunction<Component, SOURCE, Component> componentUpdateFunction) Creates a new ComponentRenderer that uses the componentFunction to generate new
Component
instances, and a componentUpdateFunction to update existingComponent
instances.ComponentRenderer
(SerializableSupplier<COMPONENT> componentSupplier) Creates a new ComponentRenderer that uses the componentSupplier to generate new
Component
instances.ComponentRenderer
(SerializableSupplier<COMPONENT> componentSupplier, SerializableBiConsumer<COMPONENT, SOURCE> itemConsumer) Creates a new ComponentRenderer that uses the componentSupplier to generate new
Component
instances, and the itemConsumer to set the related items. -
Method Summary
Modifier and TypeMethodDescriptioncreateComponent
(SOURCE item) Creates a component for a given object model item.
protected String
Returns the Lit template expression used to render items.
render
(Element owner, DataKeyMapper<SOURCE> keyMapper, String rendererName) Registers a renderer function with the given name to the given container element.
updateComponent
(Component currentComponent, SOURCE item) Called when the item is updated.
Methods inherited from class com.vaadin.flow.data.renderer.LitRenderer
getValueProviders, of, withFunction, withFunction, withProperty
-
Constructor Details
-
ComponentRenderer
public ComponentRenderer(SerializableSupplier<COMPONENT> componentSupplier, SerializableBiConsumer<COMPONENT, SOURCE> itemConsumer) Creates a new ComponentRenderer that uses the componentSupplier to generate new
Component
instances, and the itemConsumer to set the related items.Some components may support several rendered components at once, so different component instances should be created for each different item for those components.
Parameters:
componentSupplier
- a supplier that can generate new component instancesitemConsumer
- a setter for the corresponding item for the rendered component -
ComponentRenderer
Creates a new ComponentRenderer that uses the componentSupplier to generate new
Component
instances.This constructor is a convenient way of providing components to a template when the actual model item doesn't matter for the component instance.
Some components may support several rendered components at once, so different component instances should be created for each different item for those components.
Parameters:
componentSupplier
- a supplier that can generate new component instances -
ComponentRenderer
Creates a new ComponentRenderer that uses the componentFunction to generate new
Component
instances. The function takes a model item and outputs a component instance.Some components may support several rendered components at once, so different component instances should be created for each different item for those components.
Parameters:
componentFunction
- a function that can generate new component instancesSee Also:
-
ComponentRenderer
public ComponentRenderer(SerializableFunction<SOURCE, COMPONENT> componentFunction, SerializableBiFunction<Component, SOURCE, Component> componentUpdateFunction) Creates a new ComponentRenderer that uses the componentFunction to generate new
Component
instances, and a componentUpdateFunction to update existingComponent
instances.The componentUpdateFunction can return a different component than the one previously created. In those cases, the new instance is used, and the old is discarded.
Some components may support several rendered components at once, so different component instances should be created for each different item for those components.
Parameters:
componentFunction
- a function that can generate new component instancescomponentUpdateFunction
- a function that can update the existing component instance for the item, or generate a new component based on the item update. When the function isnull
, the componentFunction is always used instead
-
-
Method Details
-
getTemplateExpression
Description copied from class:
LitRenderer
Returns the Lit template expression used to render items.
Overrides:
getTemplateExpression
in classLitRenderer<SOURCE>
Returns:
the template expression
-
render
public Rendering<SOURCE> render(Element owner, DataKeyMapper<SOURCE> keyMapper, String rendererName) Description copied from class:
Renderer
Registers a renderer function with the given name to the given container element. Creates the setup to handle rendering of individual data items as requested by the renderer function invocation.
Overrides:
render
in classLitRenderer<SOURCE>
Parameters:
owner
- the element which accepts the renderer function on the client.keyMapper
- mapper used internally to fetch items by key and to provide keys for given items.rendererName
- name of the renderer function the container element acceptsReturns:
the context of the rendering, that can be used by the components to provide extra customization
-
createComponent
Creates a component for a given object model item. Subclasses can override this method to provide specific behavior.
Parameters:
item
- the model item, possiblynull
Returns:
a component instance representing the provided item
-
updateComponent
Called when the item is updated. By default, a new
Component
is created (viacreateComponent(Object)
) when the item is updated, but setting a update function via theComponentRenderer(SerializableFunction, SerializableBiFunction)
can change the behavior.Parameters:
currentComponent
- the current component used to render the item, notnull
item
- the updated itemReturns:
the component that should be used to render the updated item. The same instance can be returned, or a totally new one, but not
null
.
-