Laurent Grégoire
Laurent Grégoire

Reputation: 4146

Get the HTML output data from a wicket component

I'm currently writing a web widget, and I would like to fill the content of this widget with some HTML data generated by a wicket component on my server.

To do that, the server will output the HTML data via JSONP. So far so good.

However I need to get this HTML data. How can I get on the server the HTML output from some wicket component?

Upvotes: 2

Views: 1255

Answers (2)

Mar Cel
Mar Cel

Reputation: 420

I dont know if this can be applied to your configuration, but I am using a view lines of code to retrieve rendered html which I wrote some time ago for building html based emails to be able to use wicket components in it

protected final String renderPage(Component page)  {
        final Response oldResponse = RequestCycle.get().getResponse();
        BufferedWebResponse tempResponse = new BufferedWebResponse((WebResponse) RequestCycle.get().getOriginalResponse());

        try {
            RequestCycle.get().setResponse(tempResponse);
            page.render();
        }
        finally {
            RequestCycle.get().setResponse(oldResponse);
        }

        return tempResponse.toString();
    }

As this rendering is made within an actual webapplication cycle but independently from the actual requestcycle, it is recommended to preserve the original requestcycle. The page will be rendered in your temporary webresponse from which you can retrieve the rendered html output.

Hope this may be what you are looking for

Upvotes: 6

Nicktar
Nicktar

Reputation: 5575

You might find everything you need in this Wicket Wiki article and the linked source code: Use wicket as template engine

Although I must admit that I never tried that, just read it and remembered for further reference...

Upvotes: 0

Related Questions