Class ThymeleafViewsRenderer<T>

java.lang.Object
io.micronaut.views.thymeleaf.ThymeleafViewsRenderer<T>
Type Parameters:
T - The model type
All Implemented Interfaces:
io.micronaut.core.order.Ordered, ViewsRenderer<T,io.micronaut.http.HttpRequest<?>>

@Singleton @Requires(classes={io.micronaut.http.HttpRequest.class,io.micronaut.http.server.util.locale.HttpLocaleResolver.class}) public class ThymeleafViewsRenderer<T> extends Object implements ViewsRenderer<T,io.micronaut.http.HttpRequest<?>>
Renders templates Thymeleaf Java template engine.
Since:
1.0
Author:
Sergio del Amo, graemerocher
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected final org.thymeleaf.TemplateEngine
     
    protected final io.micronaut.http.server.util.locale.HttpLocaleResolver
     
    protected io.micronaut.core.io.ResourceLoader
     
    protected final org.thymeleaf.templateresolver.AbstractConfigurableTemplateResolver
     

    Fields inherited from interface io.micronaut.core.order.Ordered

    HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
  • Constructor Summary

    Constructors
    Constructor
    Description
    ThymeleafViewsRenderer(org.thymeleaf.templateresolver.AbstractConfigurableTemplateResolver templateResolver, org.thymeleaf.TemplateEngine templateEngine, io.micronaut.core.io.scan.ClassPathResourceLoader resourceLoader, io.micronaut.http.server.util.locale.HttpLocaleResolver httpLocaleResolver)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    exists(@NonNull String viewName)
     
    @NonNull io.micronaut.core.io.Writable
    render(@NonNull String viewName, T data, @Nullable io.micronaut.http.HttpRequest<?> request)
     
    void
    render(String viewName, org.thymeleaf.context.IContext context, Writer writer)
    Passes the arguments as is to TemplateEngine.process(String, IContext, Writer).

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface io.micronaut.core.order.Ordered

    getOrder
  • Field Details

    • templateResolver

      protected final org.thymeleaf.templateresolver.AbstractConfigurableTemplateResolver templateResolver
    • engine

      protected final org.thymeleaf.TemplateEngine engine
    • httpLocaleResolver

      protected final io.micronaut.http.server.util.locale.HttpLocaleResolver httpLocaleResolver
    • resourceLoader

      protected io.micronaut.core.io.ResourceLoader resourceLoader
  • Constructor Details

    • ThymeleafViewsRenderer

      public ThymeleafViewsRenderer(org.thymeleaf.templateresolver.AbstractConfigurableTemplateResolver templateResolver, org.thymeleaf.TemplateEngine templateEngine, io.micronaut.core.io.scan.ClassPathResourceLoader resourceLoader, io.micronaut.http.server.util.locale.HttpLocaleResolver httpLocaleResolver)
      Parameters:
      templateResolver - The template resolver
      templateEngine - The template engine
      resourceLoader - The resource loader
      httpLocaleResolver - The locale resolver
  • Method Details

    • render

      @NonNull public @NonNull io.micronaut.core.io.Writable render(@NonNull @NonNull String viewName, @Nullable T data, @Nullable @Nullable io.micronaut.http.HttpRequest<?> request)
      Specified by:
      render in interface ViewsRenderer<T,io.micronaut.http.HttpRequest<?>>
      Parameters:
      viewName - view name to be rendered
      data - response body to render it with a view
      request - HTTP request
      Returns:
      A writable where the view will be written to.
    • render

      public void render(String viewName, org.thymeleaf.context.IContext context, Writer writer)
      Passes the arguments as is to TemplateEngine.process(String, IContext, Writer).
      Parameters:
      viewName - The view name
      context - The context
      writer - The writer
    • exists

      public boolean exists(@NonNull @NonNull String viewName)
      Specified by:
      exists in interface ViewsRenderer<T,io.micronaut.http.HttpRequest<?>>
      Parameters:
      viewName - view name to be rendered
      Returns:
      true if a template can be found for the supplied view name.