com.vaadin.flow.data.renderer.
Class ComponentRenderer<COMPONENT extends Component,SOURCE>
- java.lang.Object
-
- com.vaadin.flow.data.renderer.Renderer<SOURCE>
-
- com.vaadin.flow.data.renderer.ComponentRenderer<COMPONENT,SOURCE>
-
Type Parameters:
COMPONENT
- the type of the output componentSOURCE
- the type of the input model objectAll Implemented Interfaces:
Direct Known Subclasses:
public class ComponentRenderer<COMPONENT extends Component,SOURCE> extends Renderer<SOURCE>
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>
, andcreateComponent(Object)
for components that use light-dom.Since:
1.0.
Author:
Vaadin Ltd
See Also:
-
-
Constructor Summary
Constructors Modifier Constructor and Description protected
ComponentRenderer()
Default constructor, that can be used by subclasses which supports different ways of creating components, other than those defined in the other constructors.
ComponentRenderer(SerializableFunction<SOURCE,COMPONENT> componentFunction)
Creates a new ComponentRenderer that uses the componentFunction to generate new
Component
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
All Methods Modifier and Type Method and Description COMPONENT
createComponent(SOURCE item)
Creates a component for a given object model item.
Rendering<SOURCE>
render(Element container, DataKeyMapper<SOURCE> keyMapper, Element contentTemplate)
Handles the rendering of the model objects by using the given
<template>
element in the given container.void
setComponentRendererTag(String componentRendererTag)
Sets the tag of the webcomponent used at the client-side to manage component rendering inside
<template>
.-
Methods inherited from class com.vaadin.flow.data.renderer.Renderer
getEventHandlers, getValueProviders, render, setEventHandler, setProperty
-
-
-
-
Constructor Detail
-
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
public ComponentRenderer(SerializableSupplier<COMPONENT> componentSupplier)
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
public ComponentRenderer(SerializableFunction<SOURCE,COMPONENT> componentFunction)
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 instances
-
ComponentRenderer
protected ComponentRenderer()
Default constructor, that can be used by subclasses which supports different ways of creating components, other than those defined in the other constructors.
-
-
Method Detail
-
render
public Rendering<SOURCE> render(Element container, DataKeyMapper<SOURCE> keyMapper, Element contentTemplate)
Description copied from class:
Renderer
Handles the rendering of the model objects by using the given
<template>
element in the given container.Subclasses of Renderer usually override this method to provide additional features.
Overrides:
render
in classRenderer<SOURCE>
Parameters:
container
- the element in which the template will be attached to, notnull
keyMapper
- mapper used internally to fetch items by key and to provide keys for given items. It is required when either event handlers orDataGenerator
are supportedcontentTemplate
- the<template>
element to be used for rendering in the container, notnull
Returns:
the context of the rendering, that can be used by the components to provide extra customization
-
setComponentRendererTag
public void setComponentRendererTag(String componentRendererTag)
Sets the tag of the webcomponent used at the client-side to manage component rendering inside
<template>
. By default it uses<flow-component-renderer>
.Parameters:
componentRendererTag
- the tag of the client-side webcomponent for component rendering, notnull
-
-