Uploaded image for project: 'Wicket'
  1. Wicket
  2. WICKET-4095

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

    XMLWordPrintableJSON

    Details

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

        Attachments

          Activity

            People

            • Assignee:
              mgrigorov Martin Grigorov
              Reporter:
              sneumi Stefan Neumann
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: