Get the HTML output data from a wicket component

旧巷老猫 提交于 2019-12-22 13:51:07

问题


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?


回答1:


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




回答2:


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...



来源:https://stackoverflow.com/questions/10912645/get-the-html-output-data-from-a-wicket-component

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!