Package com.vaadin.flow.data.renderer
Interface CompiledLitTemplate
- All Superinterfaces:
JsSnippet,Serializable
@JsFunctionParameterNames({"html","root","live","appId","itemKey","model","item","index","functions"})
public interface CompiledLitTemplate
extends JsSnippet
A Lit template that renders an item, declared by a method of a
JsDefinition interface. The build collects the
JavaScript into the bundle, so the browser does not compile the template from
a string, which a content security policy without unsafe-eval
forbids.
The JavaScript is the body of a function that returns the template:
@JsDefinition
interface PersonTemplates extends Serializable {
@JsExpression("""
return html`<span title=${$0} @click=${functions.select}>
${item.name}</span>`;
""")
CompiledLitTemplate name(String title);
}
grid.addColumn(LitRenderer
.<Person> of(JsSnippets.of(PersonTemplates.class).name("Name"))
.withProperty("name", Person::getName)
.withFunction("select", person -> select(person)));
The function is called with these arguments:
html: the tag of a Lit template. The markup is written between backticks after it, ashtml`...`, and each${...}in it is a binding to a JavaScript value: text content (${item.name}), an attribute (title=${...}), a property of the element (.disabled=${...}) or an event listener (@click=${...}). Lit creates the elements of the markup once and afterwards only updates the bindings whose values changed.live: a Lit directive for a property that the user can also change in the browser, such ascheckedof a checkbox. A binding written as.checked=${live(item.checked)}compares the value with the current value of the element, rather than with the last rendered value, so that the value of the server is set again after the user has changed it.root: the element the item is rendered intoappId: the id of the applicationitemKey,model,index: the key of the item, the model of the row of the component, for example itsexpandedstate in a tree grid, and the index of the itemitem: an object with the properties added withLitRenderer.withProperty(java.lang.String, com.vaadin.flow.function.ValueProvider<SOURCE, ?>), rather than the Java object of the itemfunctions: the functions added withLitRenderer.withFunction(java.lang.String, com.vaadin.flow.function.SerializableConsumer<SOURCE>), as members, which call the server
$0,
$1, … They are sent to the browser when the renderer is
set up, so they are the same for every item.- Since:
- 25.4
- See Also: