示例#1
0
  public void render(FacesContext context) throws FacesException {
    if (context.getResponseComplete()) return;

    Application app = context.getApplication();
    ViewHandler view = app.getViewHandler();

    beforePhase(context, PhaseId.RENDER_RESPONSE);

    try {
      if (log.isLoggable(Level.FINER)) log.finer(context.getViewRoot() + " before render view");

      view.renderView(context, context.getViewRoot());
    } catch (java.io.IOException e) {
      if (sendError(context, "renderView", e)) return;

      throw new FacesException(e);
    } catch (RuntimeException e) {
      if (sendError(context, "renderView", e)) return;

      throw e;
    } finally {
      afterPhase(context, PhaseId.RENDER_RESPONSE);

      logMessages(context);
    }
  }
示例#2
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");
    }
  }
 public void renderView(FacesContext context, UIViewRoot viewRoot)
     throws IOException, FacesException {
   String viewId = viewRoot.getViewId();
   if (!context.getResponseComplete() && isMapped(viewId)) {
     NavigationHandler nh = context.getApplication().getNavigationHandler();
     ViewHandler vh = context.getApplication().getViewHandler();
     String action = (String) context.getExternalContext().getRequestParameterMap().get("action");
     String outcome =
         (String) context.getExternalContext().getRequestParameterMap().get("outcome");
     if (action != null) {
       String method = extractMethodName(action);
       MethodBinding mb =
           context.getApplication().createMethodBinding("#{" + action + "}", new Class[0]);
       outcome = mb.invoke(context, new Object[0]).toString();
       nh.handleNavigation(context, method, outcome);
       if (!context.getResponseComplete() && context.getViewRoot().equals(viewRoot)) {
         throw new FacesException(
             "No navigation rules from viewId="
                 + viewId
                 + ", action="
                 + action
                 + ", outcome="
                 + outcome
                 + " found.");
       }
     } else {
       nh.handleNavigation(context, null, outcome);
       if (!context.getResponseComplete() && context.getViewRoot().equals(viewRoot)) {
         throw new FacesException(
             "No navigation rules from viewId=" + viewId + ", outcome=" + outcome + " found.");
       }
     }
     if (!context.getResponseComplete()) {
       vh.renderView(context, context.getViewRoot());
     }
     ;
   } else {
     viewHandler.renderView(context, viewRoot);
   }
 }
 public void renderView(FacesContext context, UIViewRoot root) throws IOException, FacesException {
   // SAK-20286 start
   // Get the request
   HttpServletRequest req = (HttpServletRequest) context.getExternalContext().getRequest();
   String requestURI = req.getRequestURI();
   // Make the attribute name unique to the request
   String attrName = "sakai.jsf.tool.URL.loopDetect.viewId-" + requestURI;
   // Try to fetch the attribute
   Object attribute = req.getAttribute(attrName);
   // If the attribute is null, this is the first request for this view
   if (attribute == null) {
     req.setAttribute(attrName, "true");
   } else if ("true".equals(attribute)) { // A looping request is detected.
     HttpServletResponse res = (HttpServletResponse) context.getExternalContext().getResponse();
     // Send a 404
     res.sendError(404, "File not found: " + requestURI);
   }
   // SAK-20286 end
   m_wrapped.renderView(context, root);
 }
 @Override
 public void beforePhase(PhaseEvent event) {
   FacesContext facesContext = event.getFacesContext();
   ExternalContext externalContext = facesContext.getExternalContext();
   HttpSession httpSession = (HttpSession) externalContext.getSession(false);
   boolean newSession = (httpSession == null) || (httpSession.isNew());
   boolean postBack = !externalContext.getRequestParameterMap().isEmpty();
   boolean timedOut = postBack && newSession;
   if (timedOut) {
     Application application = facesContext.getApplication();
     ViewHandler viewHandler = application.getViewHandler();
     UIViewRoot view = viewHandler.createView(facesContext, "/main.xhtml");
     facesContext.setViewRoot(view);
     facesContext.renderResponse();
     try {
       viewHandler.renderView(facesContext, view);
       facesContext.responseComplete();
     } catch (Exception e) {
       throw new FacesException("Session timed out", e);
     }
   }
 }