Interface TemplateInstance

All Known Implementing Classes:
ForwardingTemplateInstance, ResultsCollectingTemplateInstance, TemplateInstanceBase

public interface TemplateInstance
Represents an instance of Template.

This construct is not thread-safe.

  • Field Details

  • Method Details

    • data

      default TemplateInstance data(Object data)
      Set the the root data object. Invocation of this method removes any data set previously by data(String, Object) and computedData(String, Function).
      Parameters:
      data -
      Returns:
    • data

      default TemplateInstance data(String key, Object data)
      Put the data in a map. The map will be used as the root context object during rendering. Remove the root data object previously set by data(Object).
      Parameters:
      key -
      data -
      Returns:
      self
    • computedData

      default TemplateInstance computedData(String key, Function<String,Object> function)
      Associates the specified mapping function with the specified key. The function is applied each time a value for the given key is requested. Also removes the root data object previously set by data(Object).

      If the key is already associated with a value using the data(String, Object) method then the mapping function is never used.

      Parameters:
      key -
      function -
      Returns:
      self
    • setAttribute

      default TemplateInstance setAttribute(String key, Object value)
      Parameters:
      key -
      value -
      Returns:
      self
    • getAttribute

      default Object getAttribute(String key)
      Parameters:
      key -
      Returns:
      the attribute or null
    • render

      default String render()
      Triggers rendering. Note that this method blocks the current thread!
      Returns:
      the rendered template as string
    • renderAsync

      default CompletionStage<String> renderAsync()
      Triggers rendering.
      Returns:
      a completion stage that is completed once the rendering finished
    • createMulti

      default io.smallrye.mutiny.Multi<String> createMulti()
      Create a new Multi that can be used to consume chunks of the rendered template. In particular, each item represents a part of the rendered template.

      This operation does not trigger rendering. Instead, each subscription triggers a new rendering of the template.

      Returns:
      a new Multi
      See Also:
      • Multi.subscribe()
    • createUni

      default io.smallrye.mutiny.Uni<String> createUni()
      Create a new Uni that can be used to consume the rendered template.

      This operation does not trigger rendering. Instead, each subscription triggers a new rendering of the template.

      Returns:
      a new Uni
      See Also:
      • Uni.subscribe()
    • consume

      default CompletionStage<Void> consume(Consumer<String> consumer)
      Triggers rendering.
      Parameters:
      consumer - To consume chunks of the rendered template
      Returns:
      a completion stage that is completed once the rendering finished
    • getTimeout

      default long getTimeout()
      Returns:
      the timeout
      See Also:
    • getTemplate

      default Template getTemplate()
      Returns:
      the original template
    • getFragment

      default Template getFragment(String id)
      Parameters:
      id -
      Returns:
      the fragment or null
      See Also:
    • onRendered

      default TemplateInstance onRendered(Runnable action)
      Register an action that is performed after the rendering is finished.
      Parameters:
      action -
      Returns:
      self
    • setLocale

      default TemplateInstance setLocale(String locale)
      Sets the locale attribute that can be used to localize parts of the template, i.e. to specify the locale for all message bundle expressions in the template.
      Parameters:
      locale - a language tag
      Returns:
      self
    • setLocale

      default TemplateInstance setLocale(Locale locale)
      Sets the locale attribute that can be used to localize parts of the template, i.e. to specify the locale for all message bundle expressions in the template.
      Parameters:
      locale - a Locale instance
      Returns:
      self
    • setVariant

      default TemplateInstance setVariant(Variant variant)
      Sets the variant attribute that can be used to select a specific variant of the template.
      Parameters:
      variant - the variant
      Returns:
      self