Ejemplo n.º 1
0
  public void execute(FacesContext facesContext) throws FacesException {

    if (LOGGER.isLoggable(Level.FINE)) {
      LOGGER.fine("Entering RenderResponsePhase");
    }
    if (LOGGER.isLoggable(Level.FINE)) {
      LOGGER.fine("About to render view " + facesContext.getViewRoot().getViewId());
    }
    // For requests intended to produce a partial response, we need prohibit
    // writing any content outside of the view itself (f:view).
    PartialViewContext partialViewContext = facesContext.getPartialViewContext();
    if (partialViewContext.isAjaxRequest()) {
      OnOffResponseWrapper onOffResponse = new OnOffResponseWrapper(facesContext);
      onOffResponse.setEnabled(false);
    }

    try {

      ViewHandler vh = facesContext.getApplication().getViewHandler();

      ViewDeclarationLanguage vdl =
          vh.getViewDeclarationLanguage(facesContext, facesContext.getViewRoot().getViewId());
      if (vdl != null) {
        vdl.buildView(facesContext, facesContext.getViewRoot());
      }

      boolean viewIdsUnchanged;
      do {
        String beforePublishViewId = facesContext.getViewRoot().getViewId();
        // the before render event on the view root is a special case to keep door open for
        // navigation
        // this must be called *after* PDL.buildView() and before VH.renderView()
        facesContext
            .getApplication()
            .publishEvent(facesContext, PreRenderViewEvent.class, facesContext.getViewRoot());
        String afterPublishViewId = facesContext.getViewRoot().getViewId();
        viewIdsUnchanged =
            beforePublishViewId == null && afterPublishViewId == null
                || (beforePublishViewId != null && afterPublishViewId != null)
                    && beforePublishViewId.equals(afterPublishViewId);
      } while (!viewIdsUnchanged);

      // render the view
      vh.renderView(facesContext, facesContext.getViewRoot());

    } catch (IOException e) {
      throw new FacesException(e.getMessage(), e);
    }

    if (LOGGER.isLoggable(Level.FINEST)) {
      LOGGER.log(
          Level.FINEST,
          "+=+=+=+=+=+= View structure printout for " + facesContext.getViewRoot().getViewId());
      DebugUtil.printTree(facesContext.getViewRoot(), LOGGER, Level.FINEST);
    }

    if (LOGGER.isLoggable(Level.FINE)) {
      LOGGER.fine("Exiting RenderResponsePhase");
    }
  }
Ejemplo n.º 2
0
  /** @see javax.faces.context.PartialViewContext#processPartial(javax.faces.event.PhaseId)) */
  @Override
  public void processPartial(PhaseId phaseId) {
    Collection<String> executeIds = getExecuteIds();
    Collection<String> renderIds = getRenderIds();
    UIViewRoot viewRoot = ctx.getViewRoot();

    if (phaseId == PhaseId.APPLY_REQUEST_VALUES
        || phaseId == PhaseId.PROCESS_VALIDATIONS
        || phaseId == PhaseId.UPDATE_MODEL_VALUES) {

      // Skip this processing if "none" is specified in the render list,
      // or there were no execute phase client ids.

      if (executeIds == null || executeIds.isEmpty()) {
        // RELEASE_PENDING LOG ERROR OR WARNING
        return;
      }

      try {
        processComponents(viewRoot, phaseId, executeIds, ctx);
      } catch (Exception e) {
        // RELEASE_PENDING LOG EXCEPTION
      }

      // If we have just finished APPLY_REQUEST_VALUES phase, install the
      // partial response writer.  We want to make sure that any content
      // or errors generated in the other phases are written using the
      // partial response writer.
      //
      if (phaseId == PhaseId.APPLY_REQUEST_VALUES) {
        PartialResponseWriter writer = getPartialResponseWriter();
        ctx.setResponseWriter(writer);
      }

    } else if (phaseId == PhaseId.RENDER_RESPONSE) {

      try {
        //
        // We re-enable response writing.
        //
        OnOffResponseWrapper onOffResponse = new OnOffResponseWrapper(ctx);
        onOffResponse.setEnabled(true);
        PartialResponseWriter writer = getPartialResponseWriter();
        ResponseWriter orig = ctx.getResponseWriter();
        ctx.getAttributes().put(ORIGINAL_WRITER, orig);
        ctx.setResponseWriter(writer);

        ExternalContext exContext = ctx.getExternalContext();
        exContext.setResponseContentType("text/xml");
        exContext.addResponseHeader("Cache-Control", "no-cache");
        writer.startDocument();
        if (isRenderAll()) {
          renderAll(ctx, viewRoot);
          renderState(ctx);
          writer.endDocument();
          return;
        }

        // Skip this processing if "none" is specified in the render list,
        // or there were no render phase client ids.
        if (renderIds == null || renderIds.isEmpty()) {
        } else {
          processComponents(viewRoot, phaseId, renderIds, ctx);
        }

        renderState(ctx);

        writer.endDocument();
      } catch (IOException ex) {
        this.cleanupAfterView();
      } catch (RuntimeException ex) {
        this.cleanupAfterView();
        // Throw the exception
        throw ex;
      }
    }
  }