com.vaadin.flow.data.renderer.
Class BasicRenderer<SOURCE,TARGET>
- java.lang.Object
-
- com.vaadin.flow.data.renderer.Renderer<SOURCE>
-
- com.vaadin.flow.data.renderer.ComponentRenderer<Component,SOURCE>
-
- com.vaadin.flow.data.renderer.BasicRenderer<SOURCE,TARGET>
-
Type Parameters:
SOURCE
- the type of the item used inside the rendererTARGET
- the type of the output object, such as Number or LocalDateAll Implemented Interfaces:
Direct Known Subclasses:
LocalDateRenderer
,LocalDateTimeRenderer
,NativeButtonRenderer
,NumberRenderer
public abstract class BasicRenderer<SOURCE,TARGET> extends ComponentRenderer<Component,SOURCE>
Abstract renderer used as the base implementation for renderers that outputs a simple value in the UI, such as
NumberRenderer
andLocalDateRenderer
.Author:
Vaadin Ltd
See Also:
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
BasicRenderer(ValueProvider<SOURCE,TARGET> valueProvider)
Builds a new template renderer using the value provider as the source of values to be rendered.
-
Method Summary
All Methods Modifier and Type Method Description Component
createComponent(SOURCE item)
Creates a component for a given object model item.
protected String
getFormattedValue(TARGET object)
Gets the String representation of the target object, to be used inside the template.
protected String
getTemplateForProperty(String property, Rendering<SOURCE> context)
Gets the template String for a given property.
protected String
getTemplatePropertyName(Rendering<SOURCE> context)
Gets the name of the property to be transmitted and used inside the template.
protected ValueProvider<SOURCE,TARGET>
getValueProvider()
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.-
Methods inherited from class com.vaadin.flow.data.renderer.ComponentRenderer
setComponentRendererTag, updateComponent
-
Methods inherited from class com.vaadin.flow.data.renderer.Renderer
getEventHandlers, getValueProviders, render, setEventHandler, setProperty
-
-
-
-
Constructor Detail
-
BasicRenderer
protected BasicRenderer(ValueProvider<SOURCE,TARGET> valueProvider)
Builds a new template renderer using the value provider as the source of values to be rendered.
Parameters:
valueProvider
- the callback to provide a objects to the renderer, notnull
-
-
Method Detail
-
getValueProvider
protected ValueProvider<SOURCE,TARGET> getValueProvider()
-
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 classComponentRenderer<Component,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
-
getTemplatePropertyName
protected String getTemplatePropertyName(Rendering<SOURCE> context)
Gets the name of the property to be transmitted and used inside the template. By default, it generates a unique name by using the class name of the renderer and the node id of the template element.
This method is only called when
render(Element, DataKeyMapper, Element)
is invoked.Parameters:
context
- the rendering contextReturns:
the property name to be used in template data bindings
See Also:
-
getTemplateForProperty
protected String getTemplateForProperty(String property, Rendering<SOURCE> context)
Gets the template String for a given property.
This method is only called when
render(Element, DataKeyMapper, Element)
is invoked.Parameters:
property
- the property to be used inside the templatecontext
- the rendering contextReturns:
the template string to be used inside a
<template>
elementSee Also:
-
createComponent
public Component createComponent(SOURCE item)
Description copied from class:
ComponentRenderer
Creates a component for a given object model item. Subclasses can override this method to provide specific behavior.
Overrides:
createComponent
in classComponentRenderer<Component,SOURCE>
Parameters:
item
- the model item, possiblynull
Returns:
a component instance representing the provided item
-
getFormattedValue
protected String getFormattedValue(TARGET object)
Gets the String representation of the target object, to be used inside the template.
By default it uses
String.valueOf(Object)
of the object.Parameters:
object
- the target objectReturns:
the string representation of the object
-
-