/** * Outputs the HTML tags of the given component to the given writer. * * @param path the request path. If null, the servlet path is assumed. * @param out the output (never null). * @param richlet the richlet to run. If you have only one component to show and no need process * it under an execution, you could use {@link #render(javax.servlet.ServletContext, * javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, * org.zkoss.zk.ui.Component, String, java.io.Writer)} instead. * @since 5.0.5 */ public static final void render( ServletContext ctx, HttpServletRequest request, HttpServletResponse response, Richlet richlet, String path, Writer out) throws ServletException, IOException { if (path == null) path = Https.getThisServletPath(request); WebManager webman = WebManager.getWebManagerIfAny(ctx); if (webman == null) { final String ATTR = "org.zkoss.zkplus.embed.updateURI"; String updateURI = Library.getProperty(ATTR); if (updateURI == null) updateURI = "/zkau"; else updateURI = Utils.checkUpdateURI(updateURI, ATTR); webman = new WebManager(ctx, updateURI); } final Session sess = WebManager.getSession(ctx, request); final WebApp wapp = sess.getWebApp(); final WebAppCtrl wappc = (WebAppCtrl) wapp; final Object old = I18Ns.setup(sess, request, response, wapp.getConfiguration().getResponseCharset()); Execution exec = null; try { final Desktop desktop = webman.getDesktop(sess, request, response, path, true); if (desktop == null) // forward or redirect return; final RequestInfo ri = new RequestInfoImpl(wapp, sess, desktop, request, PageDefinitions.getLocator(wapp, path)); sess.setAttribute(Attributes.GAE_FIX, new Integer(0)); ((SessionCtrl) sess).notifyClientRequest(true); final UiFactory uf = wappc.getUiFactory(); final Page page = WebManager.newPage(uf, ri, richlet, response, path); exec = new ExecutionImpl(ctx, request, response, desktop, page); exec.setAttribute(Attributes.PAGE_REDRAW_CONTROL, "page"); exec.setAttribute(Attributes.PAGE_RENDERER, new PageRenderer(exec)); wappc.getUiEngine().execNewPage(exec, richlet, page, out); // no need to set device type here, since UiEngine will do it later } finally { I18Ns.cleanup(request, old); if (exec != null) { exec.removeAttribute(Attributes.PAGE_REDRAW_CONTROL); exec.removeAttribute(Attributes.PAGE_RENDERER); } } }
// @Override public void render(Page page, Writer out) throws IOException { final Desktop desktop = _exec.getDesktop(); out.write("<script type=\"text/javascript\">zkpb('"); out.write(page.getUuid()); out.write("','"); out.write(desktop.getId()); out.write("','"); out.write(getContextURI()); out.write("','"); out.write(desktop.getUpdateURI(null)); out.write("','"); out.write(desktop.getRequestPath()); out.write('\''); String style = page.getStyle(); if (style != null && style.length() > 0) { out.write(",{style:'"); out.write(style); out.write("'}"); } out.write(");zkpe();</script>\n"); for (Component root = page.getFirstRoot(); root != null; root = root.getNextSibling()) { // HtmlPageRenders.outStandalone(_exec, root, out); } }
private String getContextURI() { if (_exec != null) { String s = _exec.encodeURL("/"); int j = s.lastIndexOf('/'); // might have jsessionid=... return j >= 0 ? s.substring(0, j) + s.substring(j + 1) : s; } return ""; }