Adding wicket-example for rendering a Page in the current requestCycle
----------------------------------------------------------------------

                 Key: WICKET-4095
                 URL: https://issues.apache.org/jira/browse/WICKET-4095
             Project: Wicket
          Issue Type: Task
          Components: wicket-examples
    Affects Versions: 1.5.0
            Reporter: Stefan Neumann
            Priority: Trivial


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();
    }

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: 
https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Reply via email to