Package com.storedobject.ui.util
Class HtmlTemplate
java.lang.Object
com.vaadin.flow.component.Component
com.storedobject.ui.util.HtmlTemplate
- All Implemented Interfaces:
com.vaadin.flow.component.AttachNotifier,com.vaadin.flow.component.DetachNotifier,com.vaadin.flow.component.HasElement,com.vaadin.flow.component.HasStyle,Serializable
- Direct Known Subclasses:
TemplateLayout
@Tag("div")
public abstract class HtmlTemplate
extends com.vaadin.flow.component.Component
Abstract base class for a component that is initialized based on the contents
of an HTML template. The HTML content is read to create a
server-side Element tree. For instance fields marked with @
Id, an
element with the corresponding id attribute value is identified, upgraded to
a component of the type defined by the field and the component instance is
set as the field value. However, it is possible to custom-create the component instance by
overriding the createComponentForId(String) or createComponentForId(String, String) method.- Author:
- Leif Åstrand (Vaadin Ltd.). Enhanced by Syam.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceRepresents a functional interface that provides methods for creating components and SVG elements based on unique identifiers or tags.static interfaceCallback for creating an input stream on demand.static interfaceRepresents a supplier functional interface for providing style information. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedCreates a new HTML template based on the content of theTextContentthat has the same name of this class.protectedCreates a new HTML template based on the content of theTextContentprovided.protectedHtmlTemplate(String textContentName) Creates a new HTML template based on the content of theTextContentprovided.protectedHtmlTemplate(String cacheKey, HtmlTemplate.StreamSupplier streamSupplier) Creates a new HTML template based on HTML read from an input stream.protectedHtmlTemplate(String cacheKey, HtmlTemplate.StreamSupplier streamSupplier, HtmlTemplate.StyleSupplier styleSupplier) Creates a new HTML template based on HTML read from an input stream.protectedHtmlTemplate(Supplier<String> contentSupplier) Creates a new HTML template based on the content provided by a supplier. -
Method Summary
Modifier and TypeMethodDescriptionvoidbuild()Build the template.static voidClears the cache used by the HTML template parser.protected com.vaadin.flow.component.ComponentCreates aComponentfor the given identifier.protected com.vaadin.flow.component.ComponentcreateComponentForId(String id, String tag) Creates aComponentfor the given identifier and tag.protected com.vaadin.flow.component.SvgcreateSvgForId(String id) Creates an SVG element for the given identifier.booleanChecks whether the HTML template has been successfully created.protected voidonAttach(com.vaadin.flow.component.AttachEvent attachEvent) voidsetComponentCreator(HtmlTemplate.ComponentCreator componentCreator) Sets theComponentCreatorthat will be used to create components for specific IDs within the HTML template.voidSets the view object for the current template.Methods inherited from class com.vaadin.flow.component.Component
addListener, findAncestor, fireEvent, from, get, getChildren, getElement, getEventBus, getId, getListeners, getLocale, getParent, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getUI, hasListener, isAttached, isTemplateMapped, isVisible, onDetach, onEnabledStateChanged, removeFromParent, scrollIntoView, scrollIntoView, set, setElement, setId, setVisibleMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.vaadin.flow.component.AttachNotifier
addAttachListenerMethods inherited from interface com.vaadin.flow.component.DetachNotifier
addDetachListenerMethods inherited from interface com.vaadin.flow.component.HasStyle
addClassName, addClassNames, getClassName, getClassNames, getStyle, hasClassName, removeClassName, removeClassNames, setClassName, setClassName
-
Constructor Details
-
HtmlTemplate
protected HtmlTemplate()Creates a new HTML template based on the content of theTextContentthat has the same name of this class. -
HtmlTemplate
Creates a new HTML template based on the content of theTextContentprovided.- Parameters:
tc- Text content.
-
HtmlTemplate
Creates a new HTML template based on the content of theTextContentprovided.- Parameters:
textContentName- Text content name.
-
HtmlTemplate
-
HtmlTemplate
Creates a new HTML template based on HTML read from an input stream.- Parameters:
cacheKey- the key to use for potentially caching the result of reading and parsing the template, ornullnever cache the resultstreamSupplier- an input stream supplier that will be used if caching isn't used or if there is a cache miss notnull
-
HtmlTemplate
protected HtmlTemplate(String cacheKey, HtmlTemplate.StreamSupplier streamSupplier, HtmlTemplate.StyleSupplier styleSupplier) Creates a new HTML template based on HTML read from an input stream.- Parameters:
cacheKey- the key to use for potentially caching the result of reading and parsing the template, ornullnever cache the resultstreamSupplier- an input stream supplier that will be used if caching isn't used or if there is a cache miss notnull
-
-
Method Details
-
onAttach
protected void onAttach(com.vaadin.flow.component.AttachEvent attachEvent) - Overrides:
onAttachin classcom.vaadin.flow.component.Component
-
build
public void build()Build the template. This method is called automatically when the template is attached to the UI. -
isCreated
public boolean isCreated()Checks whether the HTML template has been successfully created.- Returns:
- true if the template has been created, false otherwise
-
setView
Sets the view object for the current template.- Parameters:
view- the view object to be associated with this template
-
setComponentCreator
Sets theComponentCreatorthat will be used to create components for specific IDs within the HTML template.- Parameters:
componentCreator- theComponentCreatorinstance responsible for creating components for specified IDs
-
createComponentForId
Creates aComponentfor the given identifier. If aComponentCreatoris set, the creation is delegated to it. Otherwise, a defaultISpaninstance is created with the ID embedded in its text.- Parameters:
id- The identifier for which theComponentis to be created.- Returns:
- The created
Component, either provided by theComponentCreatoror an instance ofISpanwith the given ID.
-
createSvgForId
Creates an SVG element for the given identifier. If aComponentCreatoris set, the creation is delegated to it. Otherwise,nullis returned.- Parameters:
id- The identifier for which to create theSvgelement.- Returns:
- The created
Svgelement if aComponentCreatoris present, ornullif noComponentCreatoris set or unable to handle the request.
-
createComponentForId
Creates aComponentfor the given identifier and tag. If aComponentCreatoris available, it delegates the creation process. If no component is created by theComponentCreatoror if the result isnullor anISpan, additional logic is applied to create an appropriate component.- Parameters:
id- The identifier for which theComponentis to be created.tag- The HTML tag used to infer the type ofComponentto create.- Returns:
- The created
Component. If no specific component can be created, anHtmlobject based on the given tag and identifier is returned.
-
clearCache
public static void clearCache()Clears the cache used by the HTML template parser. This method removes all cached entries within the `parserCache`, ensuring that subsequent parsing operations start with an empty cache. It is typically invoked to force the system to reparse and refresh template data without relying on previously cached results.
-