Package 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 LocalDate
- All Implemented Interfaces:
Serializable
- 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 asNumberRendererandLocalDateRenderer.- Author:
- Vaadin Ltd
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedBasicRenderer(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 Instance Methods Concrete Methods Modifier and Type Method Description ComponentcreateComponent(SOURCE item)Creates a component for a given object model item.protected StringgetFormattedValue(TARGET object)Gets the String representation of the target object, to be used inside the template.protected StringgetTemplateForProperty(String property, Rendering<SOURCE> context)Gets the template String for a given property.protected StringgetTemplatePropertyName(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:RendererHandles 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:
renderin classComponentRenderer<Component,SOURCE>- Parameters:
container- the element in which the template will be attached to, notnullkeyMapper- mapper used internally to fetch items by key and to provide keys for given items. It is required when either event handlers orDataGeneratorare 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 context- Returns:
- the property name to be used in template data bindings
- See Also:
Rendering.getTemplateElement()
-
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 context- Returns:
- the template string to be used inside a
<template>element - See Also:
getTemplatePropertyName(Rendering)
-
createComponent
public Component createComponent(SOURCE item)
Description copied from class:ComponentRendererCreates a component for a given object model item. Subclasses can override this method to provide specific behavior.- Overrides:
createComponentin 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 object- Returns:
- the string representation of the object
-
-