best way to externalize HTML in GWT apps?

前端 未结 14 1188
执念已碎
执念已碎 2020-12-08 03:33

What\'s the best way to externalize large quantities of HTML in a GWT app? We have a rather complicated GWT app of about 30 \"pages\"; each page has a sort

14条回答
  •  再見小時候
    2020-12-08 04:14

    The GWT Portlets framework (http://code.google.com/p/gwtportlets/) includes a WebAppContentPortlet. This serves up any content from your web app (static HTML, JSPs etc.). You can put it on a page with additional functionality in other Portlets and everything is fetched with a single async call when the page loads.

    Have a look at the source for WebAppContentPortlet and WebAppContentDataProvider to see how it is done or try using the framework itself. Here are the relevant bits of source:

    WebAppContentPortlet (client side)

    ((HasHTML)getWidget()).setHTML(html == null ? "Web App Content" : html);
    

    WebAppContentDataProvider (server side):

    HttpServletRequest servletRequest = req.getServletRequest();
    String path = f.path.startsWith("/") ? f.path : "/" + f.path;
    RequestDispatcher rd = servletRequest.getRequestDispatcher(path);
    BufferedResponse res = new BufferedResponse(req.getServletResponse());
    try {
       rd.include(servletRequest, res);
       res.getWriter().flush();
       f.html = new String(res.toByteArray(), res.getCharacterEncoding());
    } catch (Exception e) {
       log.error("Error including '" + path + "': " + e, e);
       f.html = "Error including '" + path +
            "'
    (see server log for details)"; }

提交回复
热议问题