Class LiteRenderer<SOURCE>
- Type Parameters:
SOURCE- the type of the model object used in the template
- All Implemented Interfaces:
Serializable
Renderer that uses a component instance as template. Intended as an alternative of
LitRenderer.- Author:
- Javier Godoy
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionDisable interpolation of template properties within the attributes and properties of the template components and their children.disableInterpolation(Component component) Disable interpolation of template properties within the attributes and properties of the specified component and its children.enableInterpolation(Component component) Enable interpolation of template properties within the attributes and properties of the specified component and its children.static <T> TgetItem(ComponentEvent<?> event, Class<T> type) Returns the item of an event fired on the template.static <SOURCE> LiteRenderer<SOURCE>Creates a newLiteRendererusing the specified template components.render(Element container, DataKeyMapper<SOURCE> keyMapper, String rendererName) toString()Returns a string representation of the object.withAttribute(@NonNull Component component, @NonNull String attribute, @NonNull ValueProvider<SOURCE, ?> valueProvider) Binds a dynamic attribute to a specified component inside the template..withAttribute(@NonNull Component component, @NonNull String attribute, String value) Assigns a static attribute to a specified component in the template.withListener(@NonNull Component component, @NonNull String eventType, @NonNull SerializableBiConsumer<SOURCE, elemental.json.JsonArray> handler, String... eventArguments) Registers an event listener for a DOM event on one of the child elements within the template component.withListener(@NonNull Component component, @NonNull String eventType, @NonNull SerializableConsumer<SOURCE> handler) Registers an event listener for a DOM event on one of the child elements within the template component.withProperty(@NonNull Component component, @NonNull String name, @NonNull ValueProvider<SOURCE, ?> valueProvider) Binds a dynamic property with a specified component inside the template.withProperty(@NonNull String property, @NonNull ValueProvider<SOURCE, ?> provider) Makes a Lit property available to the template component.
-
Method Details
-
toString
Returns a string representation of the object. -
render
-
of
public static <SOURCE> LiteRenderer<SOURCE> of(Component templateComponent, Component... moreTemplateComponents) Creates a newLiteRendererusing the specified template components. The renderer will automatically reflect any updates made to the components, up until the first render.${placeholder}expressions within attribute and property values will be interpolated, allowing them to dynamically reflect the same properties accessible toLitRenderer. Additionally, dynamic attributes and properties will be replaced with generated placeholders. Example:LiteRenderer.<Person>of(new Div("Name: ${item.name}")).withProperty("name", Person::getName);- Type Parameters:
SOURCE- the type of the input object used inside the template- Parameters:
templateComponent- the first template components used to render items. Must not benull.moreTemplateComponents- additional template components used to render items. Must not benull.- Returns:
- a
LiteRendererconfigured with the given template component. - Throws:
NullPointerException- if any template component isnull- See Also:
-
disableInterpolation
Disable interpolation of template properties within the attributes and properties of the template components and their children.To enable interpolation on a particular child, use
enableInterpolation(Component)on that child.- Returns:
- this instance for method chaining
- See Also:
-
disableInterpolation
Disable interpolation of template properties within the attributes and properties of the specified component and its children.To enable interpolation on a particular child, use
enableInterpolation(Component)on that child.- See Also:
-
enableInterpolation
Enable interpolation of template properties within the attributes and properties of the specified component and its children.To enable interpolation on a particular child, use
disableInterpolation(Component)on that child.- See Also:
-
withProperty
public LiteRenderer<SOURCE> withProperty(@NonNull @NonNull String property, @NonNull @NonNull ValueProvider<SOURCE, ?> provider) Makes a Lit property available to the template component. Each property is referenced inside attributes or properties of the template by using the${item.property}syntax.Example:
Any types supported byLiteRenderer.<Person>of(new Div("Name: ${item.name}")) .withProperty("name", Person::getName);LitRendererare valid types forLiteRenderer.- Parameters:
property- the name of the property used inside the template expression. Must not benull.provider- aValueProviderthat provides the actual value for the property. Must not benull.- Returns:
- this instance for method chaining
- See Also:
-
withProperty
public LiteRenderer<SOURCE> withProperty(@NonNull @NonNull Component component, @NonNull @NonNull String name, @NonNull @NonNull ValueProvider<SOURCE, ?> valueProvider) Binds a dynamic property with a specified component inside the template. The value of the property is provided by aValueProviderand will be updated based on the input object.This method invalidates any previous renderer to reflect the new property.
- Parameters:
component- the component within the template to which the property is being bound. Must not benull.name- the name of the property being bound. Must not benull.valueProvider- aValueProviderthat supplies the value of the property from the input object. Must not benull.- Returns:
- this instance for method chaining
- Throws:
IllegalArgumentException- if the provided component is not part of the template.- See Also:
-
withAttribute
public LiteRenderer<SOURCE> withAttribute(@NonNull @NonNull Component component, @NonNull @NonNull String attribute, @NonNull @NonNull ValueProvider<SOURCE, ?> valueProvider) Binds a dynamic attribute to a specified component inside the template.. The value of the property is provided by aValueProviderand will be updated based on the input object.This method invalidates any previous renderer to reflect the new attribute.
- Parameters:
component- the component within the template to which the attribute is being bound. Must not benull.attribute- the name of the attribute being bound. Must not benull.valueProvider- aValueProviderthat supplies the value of the attribute from the input object. Must not benull.- Returns:
- this instance for method chaining
- Throws:
IllegalArgumentException- if the provided component is not part of the template.- See Also:
-
withAttribute
public LiteRenderer<SOURCE> withAttribute(@NonNull @NonNull Component component, @NonNull @NonNull String attribute, String value) Assigns a static attribute to a specified component in the template. This attribute will have a fixed value and will not dynamically update based on the input object, but it can contain${placeholder}expressions allowing dynamic content to be inserted when rendered. Example:Div div = new Div("${item.firstName} ${item.lastName}"); grid.addColumn(LiteRenderer.<Person>of(div) .withProperty("firstName", Person::firstName) .withProperty("lastName", Person::lastName) .withProperty("age", Person::age) .withAttribute(div, "title", "Age: ${item.age}")- Parameters:
component- the component within the template to which the attribute is being assigned. Must not benull.attribute- the name of the attribute being assigned. Must not benull.value- the static value of the attribute. Must not benull.- Returns:
- this instance for method chaining
- Throws:
IllegalArgumentException- if the provided component is not part of the template.- See Also:
-
withListener
public LiteRenderer<SOURCE> withListener(@NonNull @NonNull Component component, @NonNull @NonNull String eventType, @NonNull @NonNull SerializableBiConsumer<SOURCE, elemental.json.JsonArray> handler, String... eventArguments) Registers an event listener for a DOM event on one of the child elements within the template component. Each DOM event can only be registered once per component. The function accepts arguments that can be consumed by the given handler.Examples:
LiteRenderer.of(new TextField()) .withListener(child, "keypress", , (item, args) -> { System.out.println("Pressed key: " + args.getString(0)); }, "e.key");- Parameters:
component- The component whose child element will receive the event listener.eventType- The type of DOM event to listen for (e.g., "click", "change").handler- A callback function to handle the event when triggeredeventArguments- One or more expressions for extracting event data. When an event is fired in the browser, the expression is evaluated and its value is sentback to the server. The expression is evaluated in a context where element refers to this element and event refersto the fired event. If multiple expressions are defined for the sameevent, their order of execution is undefined.- Returns:
- this instance for method chaining
- See Also:
-
withListener
public LiteRenderer<SOURCE> withListener(@NonNull @NonNull Component component, @NonNull @NonNull String eventType, @NonNull @NonNull SerializableConsumer<SOURCE> handler) Registers an event listener for a DOM event on one of the child elements within the template component. Each DOM event can only be registered once per component.- Parameters:
component- The component whose child element will receive the event listener.eventType- The type of DOM event to listen for (e.g., "click", "change").handler- A callback function to handle the event when triggered- Returns:
- this instance for method chaining
- See Also:
-
getItem
Returns the item of an event fired on the template.- Parameters:
event- the event fired on the template component.type- the type of the item.- Returns:
- the item of an event fired on the template
- Throws:
ClassCastException- if the captured item is not assignable totype.IllegalStateException- if no item was captured.
-