public class ComponentRenderer extends Object
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 and 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.
|
Modifier and Type | Method and Description |
---|---|
void |
destroy()
Destroy this renderer.
|
protected Request |
newRequest()
Create a new request, by default a
MockWebRequest . |
static CharSequence |
renderComponent(Component component)
Collects the Html generated by rendering a component.
|
CharSequence |
renderComponent(Supplier<Component> component)
Collects the Html generated by rendering a component.
|
static CharSequence |
renderPage(PageProvider pageProvider)
Collects the Html generated by the rendering a page.
|
CharSequence |
renderPage(Supplier<? extends Page> page)
Collects the html generated by rendering a page.
|
public ComponentRenderer()
public ComponentRenderer(Application application)
If the application was not yet initialized - e.g. it is not reused from an already running web container - it will be initialized.
application
- the application to render components inApplication.initApplication()
public void destroy()
public CharSequence renderComponent(Supplier<Component> component)
component
- supplier of the componentpublic CharSequence renderPage(Supplier<? extends Page> page)
page
- supplier of the pageprotected Request newRequest()
MockWebRequest
.public static CharSequence renderPage(PageProvider pageProvider)
Important note: Must be called on a thread bound to an application's ThreadContext
!
pageProvider
- the provider of the page class/instance and its parametersThreadContext
public static CharSequence renderComponent(Component component)
Important notes:
Fragment
instancesThreadContext
!component
- the component to render.ThreadContext
Copyright © 2006–2022 Apache Software Foundation. All rights reserved.