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
ConstructorDescriptionA renderer using a default mocked application, which never shares anything in a session never serializes anythingComponentRenderer
(Application application) A renderer using the given application. -
Method Summary
Modifier and TypeMethodDescriptionvoid
destroy()
Destroy this renderer.protected Request
Create a new request, by default aMockWebRequest
.renderComponent
(Supplier<Component> component) Collects the Html generated by rendering a component.static CharSequence
renderComponent
(Component component) Collects the Html generated by rendering a component.renderPage
(Supplier<? extends Page> page) Collects the html generated by rendering a page.static CharSequence
renderPage
(PageProvider pageProvider) Collects the Html generated by the rendering a page.
-
Constructor Details
-
ComponentRenderer
public ComponentRenderer()A renderer using a default mocked application, which- never shares anything in a session
- never serializes anything
-
ComponentRenderer
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:
-
-
Method Details
-
destroy
Destroy this renderer. -
renderComponent
Collects the Html generated by rendering a component.- Parameters:
component
- supplier of the component- Returns:
- html rendered by the panel
-
renderPage
Collects the html generated by rendering a page.- Parameters:
page
- supplier of the page- Returns:
- the html rendered by the panel
-
newRequest
Create a new request, by default aMockWebRequest
. -
renderPage
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:
-
renderComponent
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:
-