Class ComponentRenderer


  • public class ComponentRenderer
    extends java.lang.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 Summary

      Constructors 
      Constructor Description
      ComponentRenderer()
      A renderer using a default mocked application, which never shares anything in a session never serializes anything
      ComponentRenderer​(Application application)
      A renderer using the given application.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void destroy()
      Destroy this renderer.
      protected org.apache.wicket.request.Request newRequest()
      Create a new request, by default a MockWebRequest.
      java.lang.CharSequence renderComponent​(java.util.function.Supplier<Component> component)
      Collects the Html generated by rendering a component.
      static java.lang.CharSequence renderComponent​(Component component)
      Collects the Html generated by rendering a component.
      java.lang.CharSequence renderPage​(java.util.function.Supplier<? extends Page> page)
      Collects the html generated by rendering a page.
      static java.lang.CharSequence renderPage​(PageProvider pageProvider)
      Collects the Html generated by the rendering a page.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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 java.lang.CharSequence renderComponent​(java.util.function.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 java.lang.CharSequence renderPage​(java.util.function.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
      • newRequest

        protected org.apache.wicket.request.Request newRequest()
        Create a new request, by default a MockWebRequest.
      • renderPage

        public static java.lang.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 java.lang.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