Details
-
Task
-
Status: Resolved
-
Trivial
-
Resolution: Fixed
-
1.5.0
Description
As discussed on the mailing list on 11/29/2011 in "Redering to to file in wicket1.5" we dicussed to get the rendered page in a String. My running Example looks like that:
/**
- Renders a Page and returns it.
* - known issue: In my experience you cannot call it in a constructor of a page.
*/
public static String renderPageToString(
final RequestCycle requestCycle,
final Class<? extends Page> pageClass,
final PageParameters pageParameters) { final WebApplication application = WebApplication.get(); final RenderPageRequestHandler handler = new RenderPageRequestHandler( new PageProvider(pageClass, pageParameters), RedirectPolicy.NEVER_REDIRECT); final PageRenderer pageRenderer = application.getPageRendererProvider().get(handler); final Response oldResponse = requestCycle.getResponse(); // final StringResponse newResponse = new StringResponse(); final MockWebResponse mockWebResponse = new MockWebResponse(); requestCycle.setResponse(mockWebResponse); pageRenderer.respond(requestCycle); requestCycle.setResponse(oldResponse); return mockWebResponse.getTextResponse().toString(); }