Beispiel #1
0
  @Override
  public void renderView(FacesContext context, UIViewRoot root) throws IOException, FacesException {
    Components.runScheduledActions();
    if (!context.getResponseComplete()) {

      ExternalContext externalContext = context.getExternalContext();
      Object session = externalContext.getSession(false);
      Map<String, Object> requestMap = externalContext.getRequestMap();

      if (externalContext.getSessionMap().containsKey(ERROR_OCCURRED_UNDER_PORTLETS)) {
        processExceptionUnderPortlets(context);
        return;
      }

      if (AjaxUtil.isPortletRequest(context)
          && Environment.isMyFaces()
          && isNewSession(externalContext.getSession(false))) {
        processSessionExpirationUnderPortletsMyFaces(context, root, externalContext, session);
      }

      if (AjaxUtil.isPortletRequest(context)
          && Environment.isRI()
          && isNewSession(externalContext.getSession(false))) {
        processSessionExpirationUnderPortletsRI(context, root, externalContext);
      }

      boolean ajaxRequest = AjaxUtil.isAjaxRequest(context);
      if (!ajaxRequest && !AjaxUtil.isAjax4jsfRequest())
        ValidationSupportResponseWriter.resetBubbleIndex(context);

      if (ajaxRequest) {
        updateSessionExpirationFlagUnderPortlets(context, root, externalContext, requestMap);
        try {
          // HACK for MyFaces ( <f:view> tag not call renderers )
          // ServletResponse response = (ServletResponse) context
          //		.getExternalContext().getResponse();
          Object response = externalContext.getResponse();

          if (!AjaxUtil.isPortletRequest(context)) {
            try {
              response.getClass().getDeclaredMethod("resetResponse").invoke(response);
              // response.reset();
            } catch (Exception e) {
              // Do nothing - we will use directly and reset
              // wrapper
            }
          }

          if (requestMap.containsKey(SESSION_EXPIRATION_PROCESSING)) {
            super.renderView(context, root);
            // This is done for MyFaces use-case, because MyFaces doesn't call rendering methods for
            // ViewRoot
            if (!Environment.isRI()) {
              root.encodeChildren(context);
            }
            Map<String, Object> sessionMap = context.getExternalContext().getSessionMap();
            if (sessionMap != null && !sessionMap.containsKey(SESSION_SCOPED_PARAMETER)) {
              sessionMap.put(SESSION_SCOPED_PARAMETER, Boolean.TRUE.toString());
            }
            return;
          }

          if (Environment.isFacelets(context)) {
            super.renderView(context, root);
          } else {
            root.encodeBegin(context);
            if (root.getRendersChildren()) {
              root.encodeChildren(context);
            }
            root.encodeEnd(context);
          }
        } catch (RuntimeException e) {
          CommonAjaxViewRoot.processExceptionDuringAjax(context, e);
          externalContext.log(e.getMessage(), e);
        } catch (Error e) {
          CommonAjaxViewRoot.processExceptionDuringAjax(context, e);
          externalContext.log(e.getMessage(), e);
        }

      } else {

        super.renderView(context, root);
        Map<String, Object> sessionMap = context.getExternalContext().getSessionMap();
        if (sessionMap != null && !sessionMap.containsKey(SESSION_SCOPED_PARAMETER)) {
          sessionMap.put(SESSION_SCOPED_PARAMETER, Boolean.TRUE.toString());
        }

        if (AjaxUtil.isAjax4jsfRequest()) {
          Resources.processHeadResources(context);
        }
      }
    }
  }