Ejemplo n.º 1
0
  protected void addComponentToView(
      FaceletContext ctx, UIComponent parent, UIComponent c, boolean componentFound) {

    FacesContext context = ctx.getFacesContext();
    boolean suppressEvents = ComponentSupport.suppressViewModificationEvents(context);
    boolean compcomp = UIComponent.isCompositeComponent(c);

    if (suppressEvents && componentFound && !compcomp) {
      context.setProcessingEvents(false);
    }

    ComponentSupport.addComponent(ctx, parent, c);

    if (suppressEvents && componentFound && !compcomp) {
      context.setProcessingEvents(true);
    }
  }
Ejemplo n.º 2
0
  protected void doOrphanedChildCleanup(FaceletContext ctx, UIComponent parent, UIComponent c) {

    ComponentSupport.finalizeForDeletion(c);
    if (getFacetName(parent) == null) {
      FacesContext context = ctx.getFacesContext();
      boolean suppressEvents = ComponentSupport.suppressViewModificationEvents(context);

      if (suppressEvents) {
        // if the component has already been found, it will be removed
        // and added back to the view.  We don't want to publish events
        // for this case.
        context.setProcessingEvents(false);
      }
      // suppress the remove event for this case since it will be re-added
      parent.getChildren().remove(c);
      if (suppressEvents) {
        // re-enable event processing
        context.setProcessingEvents(true);
      }
    }
  }
Ejemplo n.º 3
0
  /**
   * PRECONDITION: the necessary factories have been installed in the ServletContext attr set.
   *
   * <p>
   *
   * <p>POSTCONDITION: The facesContext has been initialized with a tree.
   */
  public void execute(FacesContext facesContext) throws FacesException {

    if (LOGGER.isLoggable(Level.FINE)) {
      LOGGER.fine("Entering RestoreViewPhase");
    }
    if (null == facesContext) {
      throw new FacesException(
          MessageUtils.getExceptionMessageString(MessageUtils.NULL_CONTEXT_ERROR_MESSAGE_ID));
    }

    // If an app had explicitely set the tree in the context, use that;
    //
    UIViewRoot viewRoot = facesContext.getViewRoot();
    if (viewRoot != null) {
      if (LOGGER.isLoggable(Level.FINE)) {
        LOGGER.fine("Found a pre created view in FacesContext");
      }
      facesContext.getViewRoot().setLocale(facesContext.getExternalContext().getRequestLocale());

      // do per-component actions
      deliverPostRestoreStateEvent(facesContext);

      if (!facesContext.isPostback()) {
        facesContext.renderResponse();
      }
      return;
    }
    FacesException thrownException = null;

    try {

      // Reconstitute or create the request tree
      Map requestMap = facesContext.getExternalContext().getRequestMap();
      String viewId = (String) requestMap.get("javax.servlet.include.path_info");
      if (viewId == null) {
        viewId = facesContext.getExternalContext().getRequestPathInfo();
      }

      // It could be that this request was mapped using
      // a prefix mapping in which case there would be no
      // path_info.  Query the servlet path.
      if (viewId == null) {
        viewId = (String) requestMap.get("javax.servlet.include.servlet_path");
      }

      if (viewId == null) {
        viewId = facesContext.getExternalContext().getRequestServletPath();
      }

      if (viewId == null) {
        throw new FacesException(
            MessageUtils.getExceptionMessageString(
                MessageUtils.NULL_REQUEST_VIEW_ERROR_MESSAGE_ID));
      }

      ViewHandler viewHandler = Util.getViewHandler(facesContext);

      boolean isPostBack = (facesContext.isPostback() && !isErrorPage(facesContext));
      if (isPostBack) {
        facesContext.setProcessingEvents(false);
        // try to restore the view
        viewRoot = viewHandler.restoreView(facesContext, viewId);
        if (viewRoot == null) {
          if (is11CompatEnabled(facesContext)) {
            // 1.1 -> create a new view and flag that the response should
            //        be immediately rendered
            if (LOGGER.isLoggable(Level.FINE)) {
              LOGGER.fine("Postback: recreating a view for " + viewId);
            }
            viewRoot = viewHandler.createView(facesContext, viewId);
            facesContext.renderResponse();

          } else {
            Object[] params = {viewId};
            throw new ViewExpiredException(
                MessageUtils.getExceptionMessageString(
                    MessageUtils.RESTORE_VIEW_ERROR_MESSAGE_ID, params),
                viewId);
          }
        }

        facesContext.setViewRoot(viewRoot);
        facesContext.setProcessingEvents(true);
        if (LOGGER.isLoggable(Level.FINE)) {
          LOGGER.fine("Postback: restored view for " + viewId);
        }
      } else {
        if (LOGGER.isLoggable(Level.FINE)) {
          LOGGER.fine("New request: creating a view for " + viewId);
        }

        ViewDeclarationLanguage vdl =
            facesContext
                .getApplication()
                .getViewHandler()
                .getViewDeclarationLanguage(facesContext, viewId);
        facesContext.getAttributes().put(RIConstants.VIEWID_KEY_NAME, viewId);

        if (vdl != null) {
          // If we have one, get the ViewMetadata...
          ViewMetadata metadata = vdl.getViewMetadata(facesContext, viewId);

          if (metadata != null) { // perhaps it's not supported
            // and use it to create the ViewRoot.  This will have, at most
            // the UIViewRoot and its metadata facet.
            viewRoot = metadata.createMetadataView(facesContext);

            // Only skip to render response if there are no view parameters
            Collection<UIViewParameter> params = ViewMetadata.getViewParameters(viewRoot);
            if (params.isEmpty()) {
              facesContext.renderResponse();
            }
          }
        } else {
          facesContext.renderResponse();
        }

        if (null == viewRoot) {
          viewRoot = (Util.getViewHandler(facesContext)).createView(facesContext, viewId);
        }
        facesContext.setViewRoot(viewRoot);
        assert (null != viewRoot);
      }
    } catch (FacesException fe) {
      thrownException = fe;
    } finally {
      if (null == thrownException) {
        deliverPostRestoreStateEvent(facesContext);
      } else {
        throw thrownException;
      }
    }

    if (LOGGER.isLoggable(Level.FINE)) {
      LOGGER.fine("Exiting RestoreViewPhase");
    }
  }