Package com.vaadin.flow.data.renderer
Class LitRenderer<SOURCE>
- java.lang.Object
-
- com.vaadin.flow.data.renderer.Renderer<SOURCE>
-
- com.vaadin.flow.data.renderer.LitRenderer<SOURCE>
-
- Type Parameters:
SOURCE- the type of the model object used inside the template expression
- All Implemented Interfaces:
Serializable
@JsModule("./lit-renderer.ts") public class LitRenderer<SOURCE> extends Renderer<SOURCE>LitRenderer is aRendererthat uses a Lit-based template literal to render given model objects in the components that support the JS renderer functions API. Mainly it's intended for use withGrid,ComboBoxandVirtualList, but is not limited to these.- Since:
- 22.0.
- Author:
- Vaadin Ltd
- See Also:
of(String), https://lit.dev/docs/templates/overview/,<vaadin-combo-box>.renderer, Serialized Form
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description Map<String,com.vaadin.flow.function.SerializableConsumer<SOURCE>>getEventHandlers()Deprecated.LitRenderer doesn't support getting the event handlers.static <SOURCE> LitRenderer<SOURCE>of(String templateExpression)Creates a new LitRenderer based on the provided template expression.Rendering<SOURCE>render(com.vaadin.flow.dom.Element container, com.vaadin.flow.data.provider.DataKeyMapper<SOURCE> keyMapper)Sets up rendering of model objects inside a given {@param container} element.Rendering<SOURCE>render(com.vaadin.flow.dom.Element container, com.vaadin.flow.data.provider.DataKeyMapper<SOURCE> keyMapper, com.vaadin.flow.dom.Element contentTemplate)Deprecated.LitRenderer doesn't support elements.Rendering<SOURCE>render(com.vaadin.flow.dom.Element container, com.vaadin.flow.data.provider.DataKeyMapper<SOURCE> keyMapper, String rendererName)Sets up rendering of model objects inside a given {@param container} element.LitRenderer<SOURCE>withEventHandler(String eventHandlerName, com.vaadin.flow.function.SerializableConsumer<SOURCE> handler)Deprecated.UsewithFunction(String, SerializableConsumer)instead.LitRenderer<SOURCE>withFunction(String functionName, com.vaadin.flow.function.SerializableBiConsumer<SOURCE,elemental.json.JsonArray> handler)Adds a function that can be called from within the template expression.LitRenderer<SOURCE>withFunction(String functionName, com.vaadin.flow.function.SerializableConsumer<SOURCE> handler)Adds a function that can be called from within the template expression.LitRenderer<SOURCE>withProperty(String property, com.vaadin.flow.function.ValueProvider<SOURCE,?> provider)Makes a property available to the template expression.-
Methods inherited from class com.vaadin.flow.data.renderer.Renderer
getValueProviders, setEventHandler, setProperty
-
-
-
-
Method Detail
-
of
public static <SOURCE> LitRenderer<SOURCE> of(String templateExpression)
Creates a new LitRenderer based on the provided template expression. The expression accepts content that is allowed inside JS template literals, and works with the Lit data binding syntax.The template expression has access to:
itemthe model item being renderedindexthe index of the current item (when rendering a list)item.propertyany property of the model item exposed viawithProperty(String, ValueProvider)- any function exposed via
withFunction(String, SerializableConsumer)
Examples:
// Prints the `name` property of a person LitRenderer.<Person> of("<div>Name: ${item.name}</div>") .withProperty("name", Person::getName); // Prints the index of the item inside a repeating list LitRenderer.of("${index}");- Type Parameters:
SOURCE- the type of the input object used inside the template- Parameters:
templateExpression- the template expression used to render items, notnull- Returns:
- an initialized LitRenderer
- See Also:
withProperty(String, ValueProvider),withFunction(String, SerializableConsumer)
-
render
@Deprecated public Rendering<SOURCE> render(com.vaadin.flow.dom.Element container, com.vaadin.flow.data.provider.DataKeyMapper<SOURCE> keyMapper, com.vaadin.flow.dom.Element contentTemplate)
Deprecated.LitRenderer doesn't support elements. Don't use.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 classRenderer<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
-
getEventHandlers
@Deprecated public Map<String,com.vaadin.flow.function.SerializableConsumer<SOURCE>> getEventHandlers()
Deprecated.LitRenderer doesn't support getting the event handlers. Don't use.Description copied from class:RendererGets the event handlers linked to this renderer. The returned map is immutable.- Overrides:
getEventHandlersin classRenderer<SOURCE>- Returns:
- the mapped event handlers, never
null - See Also:
Renderer.setEventHandler(String, SerializableConsumer)
-
render
public Rendering<SOURCE> render(com.vaadin.flow.dom.Element container, com.vaadin.flow.data.provider.DataKeyMapper<SOURCE> keyMapper)
Sets up rendering of model objects inside a given {@param container} element. The model objects are rendered using the Lit template literal provided when creating this LitRenderer instance, and the Vaadin-default JS renderer function name.- Overrides:
renderin classRenderer<SOURCE>- Parameters:
container- the DOM element that supports setting a renderer functionkeyMapper- mapper used internally to fetch items by key and to provide keys for given items. It is required when either functions orDataGeneratorare supported- Returns:
- the context of the rendering, that can be used by the components to provide extra customization
-
render
public Rendering<SOURCE> render(com.vaadin.flow.dom.Element container, com.vaadin.flow.data.provider.DataKeyMapper<SOURCE> keyMapper, String rendererName)
Sets up rendering of model objects inside a given {@param container} element. The model objects are rendered using the Lit template literal provided when creating this LitRenderer instance, and a given {@param rendererName} JS renderer function.- Parameters:
container- the DOM element that supports setting a renderer functionkeyMapper- mapper used internally to fetch items by key and to provide keys for given items. It is required when either functions orDataGeneratorare supportedrendererName- name of the renderer function the container element accepts- Returns:
- the context of the rendering, that can be used by the components to provide extra customization
-
withProperty
public LitRenderer<SOURCE> withProperty(String property, com.vaadin.flow.function.ValueProvider<SOURCE,?> provider)
Makes a property available to the template expression. Each property is referenced inside the template by using the${item.property}syntax.Examples:
Any types supported by the// Regular property LitRenderer.<Person> of("<div>Name: ${item.name}</div>") .withProperty("name", Person::getName); // Property that uses a bean. Note that in this case the entire "Address" object will be sent to the template. // Note that even properties of the bean which are not used in the template are sent to the client, so use // this feature with caution. LitRenderer.<Person> of("<span>Street: ${item.address.street}</span>") .withProperty("address", Person::getAddress); // In this case only the street field inside the Address object is sent LitRenderer.<Person> of("<span>Street: ${item.street}</span>") .withProperty("street", person -> person.getAddress().getStreet());JsonSerializerare valid types for the LitRenderer.- Parameters:
property- the name of the property used inside the template expression, notnullprovider- aValueProviderthat provides the actual value for the property, notnull- Returns:
- this instance for method chaining
-
withEventHandler
public LitRenderer<SOURCE> withEventHandler(String eventHandlerName, com.vaadin.flow.function.SerializableConsumer<SOURCE> handler)
Deprecated.UsewithFunction(String, SerializableConsumer)instead.Adds an event handler that can be called from within the template expression.Examples:
The name of the event handler used in the template expression should be the name used at the eventHandlerName parameter. This name must be a valid JavaScript function name.// Standard event LitRenderer.of("<button @click=${handleClick}>Click me</button>") .withEventHandler("handleClick", object -> doSomething());- Parameters:
eventHandlerName- the name of the event handler used inside the template expression, must be alphanumeric and notnull, must not be one of the JavaScript reserved words (https://www.w3schools.com/js/js_reserved.asp)handler- the handler executed when the event handler is called, notnull- Returns:
- this instance for method chaining
- See Also:
- https://lit.dev/docs/templates/expressions/#event-listener-expressions
-
withFunction
public LitRenderer<SOURCE> withFunction(String functionName, com.vaadin.flow.function.SerializableConsumer<SOURCE> handler)
Adds a function that can be called from within the template expression.Examples:
The name of the function used in the template expression should be the name used at the functionName parameter. This name must be a valid JavaScript function name.// Standard event LitRenderer.of("<button @click=${handleClick}>Click me</button>") .withFunction("handleClick", object -> doSomething());- Parameters:
functionName- the name of the function used inside the template expression, must be alphanumeric and notnull, must not be one of the JavaScript reserved words (https://www.w3schools.com/js/js_reserved.asp)handler- the handler executed when the function is called, notnull- Returns:
- this instance for method chaining
- See Also:
- https://lit.dev/docs/templates/expressions/#event-listener-expressions
-
withFunction
public LitRenderer<SOURCE> withFunction(String functionName, com.vaadin.flow.function.SerializableBiConsumer<SOURCE,elemental.json.JsonArray> handler)
Adds a function that can be called from within the template expression. The function accepts arguments that can be consumed by the given handler.Examples:
The name of the function used in the template expression should be the name used at the functionName parameter. This name must be a valid Javascript function name.// Standard event LitRenderer.of("<button @click=${handleClick}>Click me</button>") .withFunction("handleClick", item -> doSomething()); // Function invocation with arguments LitRenderer.of("<input @keypress=${(e) => handleKeyPress(e.key)}>") .withFunction("handleKeyPress", (item, args) -> { System.out.println("Pressed key: " + args.getString(0)); });- Parameters:
functionName- the name of the function used inside the template expression, must be alphanumeric and notnull, must not be one of the JavaScript reserved words (https://www.w3schools.com/js/js_reserved.asp)handler- the handler executed when the function is called, notnull- Returns:
- this instance for method chaining
- See Also:
- https://lit.dev/docs/templates/expressions/#event-listener-expressions
-
-