Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /* Renders.java
  
  	Purpose:
  		
  	Description:
  		
  	History:
  		Tue Aug 10 08:48:59 TST 2010, Created by tomyeh
  
 Copyright (C) 2010 Potix Corporation. All Rights Reserved.
 
 */
 package org.zkoss.zkplus.embed;
 
 import java.io.Writer;
 
 
 
Utilities to embed ZK component(s) as a native JSF component, a JSP tag, Zimlet or others. It allows application developers to use the native element without knowing the existence of ZK. For example, ZK Spreadsheet for JSF is a native JSF component made in this way.

Example:


Calendar cal = new Calendar();
Renders.render(config.getServletContext(), request, response, cal, null, out);

See also Embed ZK Component in Foreign Framework.

Author(s):
tomyeh
Since:
5.0.5
 
 public class Renders {
Outputs the HTML tags of the given component to the given writer.

Parameters:
comp the component to output (never null). It might have child components.
path the request path. If null, the servlet path is assumed.
out the output (never null).
Since:
5.0.5
 
 	public static final void render(ServletContext ctx,
 	HttpServletRequest requestHttpServletResponse response,
 	Component compString pathWriter out)
 		if (comp == null)
 			throw new IllegalArgumentException();
 		render(ctxrequestresponsenew EmbedRichlet(comp), pathfalseout);
 	}
Outputs the HTML tags of the given component to the given writer. It is the same as render(ctx, request, response, richlet, path, false, out).

Parameters:
path the request path. If null, the servlet path is assumed.
out the output (never null).
richlet the richlet to run. If you have only one component to show and no need process it under an execution, you could use render(javax.servlet.ServletContext,javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse,org.zkoss.zk.ui.Component,java.lang.String,java.io.Writer) instead.
Since:
5.0.5
 
 	public static final void render(ServletContext ctx,
 	HttpServletRequest requestHttpServletResponse response,
 	Richlet richletString pathWriter out)
 		render(ctxrequestresponserichletpathfalseout);
 	}
Outputs the HTML tags of the given component to the given writer with additional control.

Parameters:
path the request path. If null, the servlet path is assumed.
out the output (never null).
richlet the richlet to run. If you have only one component to show and no need process it under an execution, you could use render(javax.servlet.ServletContext,javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse,org.zkoss.zk.ui.Component,java.lang.String,java.io.Writer) instead.
pageDOM whether to generate the DOM element to represent the page. In other words, if true is specified, the content will be enclosed with an additional DIV element representing the tag.
Since:
5.0.8
	public static final void render(ServletContext ctx,
	Richlet richletString pathboolean pageDOMWriter out)
		if (path == null)
			path = Https.getThisServletPath(request);
		final WebManager webman = WebManager.getWebManager(ctx);
		final Session sess = WebManager.getSession(ctxrequest);
		final WebApp wapp = sess.getWebApp();
		final WebAppCtrl wappc = (WebAppCtrl)wapp;
		final Object old = I18Ns.setup(sessrequestresponse,
		Execution exec = null;
		try {
			final Desktop desktop = webman.getDesktop(sessrequestresponsepathtrue);
			if (desktop == null//forward or redirect
				return;
			final RequestInfo ri = new RequestInfoImpl(
				wappsessdesktoprequest,
				PageDefinitions.getLocator(wapppath));
			final UiFactory uf = wappc.getUiFactory();
			final Page page = WebManager.newPage(ufririchletresponsepath);
			exec = new ExecutionImpl(ctxrequestresponsedesktoppage);
			exec.setAttribute(.new PageRenderer(execpageDOM));
			wappc.getUiEngine().execNewPage(execrichletpageout);
					//no need to set device type here, since UiEngine will do it later
finally {
			I18Ns.cleanup(requestold);
			if (exec != null) {
			}
		}
	}
	//Supporting classes//
	private static class EmbedRichlet extends GenericRichlet {
		private final Component _comp;
		private EmbedRichlet(Component comp) {
			 = comp;
		}
		public void service(Page page) {
		}
	}

A special page renderer that renders a page without generating the HTML tag of the page. In other words, it generates all components directly.

Author(s):
tomyeh
Since:
5.0.4
	public static class PageRenderer implements org.zkoss.zk.ui.sys.PageRenderer {
		private final Execution _exec;
		private final boolean _pageDOM;
Default constructor. It is the same as PageRenderer(Executions.getCurrent()).
		public PageRenderer() {
			this(Executions.getCurrent(), false);
		}
		public PageRenderer(Execution exec) {
			this(execfalse);
		}

Parameters:
pageDOM whether to generate the DOM element to represent the page. In other words, if true is specified, the content will be enclosed with an additional DIV element representing the tag.
Since:
5.0.8
		public PageRenderer(Execution execboolean pageDOM) {
			 = exec;
			 = pageDOM;
		}
		public void render(Page pageWriter outthrows IOException {
			out.write(HtmlPageRenders.outLangStyleSheets(nullnull));
			out.write(HtmlPageRenders.outLangJavaScripts(nullnull));
			if () {
				HtmlPageRenders.outPageContent(pageoutfalse);
				return;
			}
			final Desktop desktop = .getDesktop();
			out.write("<script class=\"z-runonce\" type=\"text/javascript\">zkpb('");
			out.write(page.getUuid());
			out.write("','");
			out.write(desktop.getId());
			out.write("','");
			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(rootout);
			}
		}
		private String getContextURI() {
			if ( != null) {
				String s = .encodeURL("/");
				int j = s.lastIndexOf('/'); //might have jsessionid=...
				return j >= 0 ? s.substring(0, j) + s.substring(j + 1): s;
			}
			return "";
		}
	}
New to GrepCode? Check out our FAQ X