/** * This is a separate method to account for handling the content after the view tag. * * <p>Create a new ResponseWriter around this response's Writer. Set it into the FacesContext, * saving the old one aside. * * <p>call encodeBegin(), encodeChildren(), encodeEnd() on the argument <code>UIViewRoot</code>. * * <p>Restore the old ResponseWriter into the FacesContext. * * <p>Write out the after view content to the response's writer. * * <p>Flush the response buffer, and remove the after view content from the request scope. * * @param context the <code>FacesContext</code> for the current request * @param viewToRender the view to render * @throws java.io.IOException if an error occurs rendering the view to the client * @throws javax.faces.FacesException if some error occurs within the framework processing */ private void doRenderView(FacesContext context, UIViewRoot viewToRender) throws IOException { if (null != associate) { associate.responseRendered(); } if (LOGGER.isLoggable(Level.FINE)) { LOGGER.log(Level.FINE, "About to render view " + viewToRender.getViewId()); } viewToRender.encodeAll(context); }
/** * @see javax.faces.view.ViewDeclarationLanguage#renderView(javax.faces.context.FacesContext, * javax.faces.component.UIViewRoot) */ public void renderView(FacesContext ctx, UIViewRoot viewToRender) throws IOException { // suppress rendering if "rendered" property on the component is // false if (!viewToRender.isRendered()) { return; } // log request if (LOGGER.isLoggable(Level.FINE)) { LOGGER.fine("Rendering View: " + viewToRender.getViewId()); } WriteBehindStateWriter stateWriter = null; try { // Only build the view if this view has not yet been built. if (!Util.isViewPopulated(ctx, viewToRender)) { this.buildView(ctx, viewToRender); } // setup writer and assign it to the ctx ResponseWriter origWriter = ctx.getResponseWriter(); if (origWriter == null) { origWriter = createResponseWriter(ctx); } stateWriter = new WriteBehindStateWriter(origWriter, ctx, responseBufferSize); ResponseWriter writer = origWriter.cloneWithWriter(stateWriter); ctx.setResponseWriter(writer); // render the view to the response writer.startDocument(); viewToRender.encodeAll(ctx); writer.endDocument(); // finish writing writer.close(); boolean writtenState = stateWriter.stateWritten(); // flush to origWriter if (writtenState) { stateWriter.flushToWriter(); } } catch (FileNotFoundException fnfe) { this.handleFaceletNotFound(ctx, viewToRender.getViewId(), fnfe.getMessage()); } catch (Exception e) { this.handleRenderException(ctx, e); } finally { if (stateWriter != null) stateWriter.release(); } }
public void testSelectOneMenu() throws Exception { this.servletRequest.setAttribute("test", this); Facelet f = FaceletFactory.getInstance().getFacelet("elparser.xml"); FacesContext faces = FacesContext.getCurrentInstance(); UIViewRoot root = faces.getViewRoot(); f.apply(faces, root); FastWriter fw = new FastWriter(); ResponseWriter rw = faces.getResponseWriter(); rw = rw.cloneWithWriter(fw); faces.setResponseWriter(rw); root.encodeAll(faces); System.out.println(fw); }
@Override public void encodeAll(FacesContext context) throws IOException { Components.runScheduledActions(); super.encodeAll(context); }