Class ComponentRenderer


  • public class ComponentRenderer
    extends Object
    A helper class for rendering components and pages.

    With the static methods of this class components and pages can be rendered on a thread already processing an Application.

    If you want to render independently from any web request processing (e.g. generating an email body on a worker thread), you can create an instance of this class.
    You may use an existing application, create a fresh one or just use the automatically created mocked application with sensible defaults.

    Note: For performance reasons instances can and should be reused, be sure to call destroy() when they are no longer needed.

    • Constructor Detail

      • ComponentRenderer

        public ComponentRenderer()
        A renderer using a default mocked application, which
        • never shares anything in a session
        • never serializes anything
      • ComponentRenderer

        public ComponentRenderer​(Application application)
        A renderer using the given application.

        If the application was not yet initialized - e.g. it is not reused from an already running web container - it will be initialized.

        Parameters:
        application - the application to render components in
        See Also:
        Application.initApplication()
    • Method Detail

      • destroy

        public void destroy()
        Destroy this renderer.
      • renderComponent

        public CharSequence renderComponent​(Supplier<Component> component)
        Collects the Html generated by rendering a component.
        Parameters:
        component - supplier of the component
        Returns:
        html rendered by the panel
      • renderPage

        public CharSequence renderPage​(Supplier<? extends Page> page)
        Collects the html generated by rendering a page.
        Parameters:
        page - supplier of the page
        Returns:
        the html rendered by the panel
      • renderPage

        public static CharSequence renderPage​(PageProvider pageProvider)
        Collects the Html generated by the rendering a page.

        Important note: Must be called on a thread bound to an application's ThreadContext!

        Parameters:
        pageProvider - the provider of the page class/instance and its parameters
        Returns:
        the html rendered by a page
        See Also:
        ThreadContext
      • renderComponent

        public static CharSequence renderComponent​(Component component)
        Collects the Html generated by rendering a component.

        Important notes:

        • this method is meant to render fresh component instances that are disposed after the html has been generate. To avoid unwanted side effects do not use it with components that are from an existing hierarchy.
        • does not support rendering Fragment instances
        • must be called on a thread bound to an application's ThreadContext!
        Parameters:
        component - the component to render.
        Returns:
        the html rendered by the component
        See Also:
        ThreadContext