Ejemplo n.º 1
0
  /**
   * @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();
    }
  }
Ejemplo n.º 2
0
  /**
   * This code is currently common to all {@link ViewHandlingStrategy} instances.
   *
   * @see ViewHandler#writeState(javax.faces.context.FacesContext)
   */
  public void writeState(FacesContext context) throws IOException {

    Util.notNull("context", context);
    if (!context.getPartialViewContext().isAjaxRequest() && !context.getViewRoot().isTransient()) {
      if (logger.isLoggable(Level.FINE)) {
        logger.fine("Begin writing marker for viewId " + context.getViewRoot().getViewId());
      }

      WriteBehindStateWriter writer = WriteBehindStateWriter.getCurrentInstance();
      if (writer != null) {
        writer.writingState();
      }
      context.getResponseWriter().write(RIConstants.SAVESTATE_FIELD_MARKER);
      if (logger.isLoggable(Level.FINE)) {
        logger.fine("End writing marker for viewId " + context.getViewRoot().getViewId());
      }
    }
  }