@Override
  public boolean visitTree(VisitContext visitContext, VisitCallback callback) {

    // First check to see whether we are visitable. If not
    // short-circuit out of this subtree, though allow the
    // visit to proceed through to other subtrees.
    if (!isVisitable(visitContext)) {
      return false;
    }

    // Clear out the row index is one is set so that
    // we start from a clean slate.
    FacesContext facesContext = visitContext.getFacesContext();

    int oldRowIndex = getRowIndex();
    setRowIndex(-1);

    // Push ourselves to EL
    pushComponentToEL(facesContext, null);

    try {

      // Visit ourselves. Note that we delegate to the
      // VisitContext to actually perform the visit.
      VisitResult result = visitContext.invokeVisitCallback(this, callback);

      // If the visit is complete, short-circuit out and end the visit
      if (result == VisitResult.COMPLETE) {
        return true;
      }

      // Visit children, short-circuiting as necessary
      if ((result == VisitResult.ACCEPT) && doVisitChildren(visitContext)) {
        setRowIndex(-1);

        if (visitFixedChildren(visitContext, callback)) {
          return true;
        }

        if (visitDataChildren(visitContext, callback)) {
          return true;
        }
      }
    } finally {

      // Clean up - pop EL and restore old row index
      popComponentFromEL(facesContext);

      try {
        setRowIndex(oldRowIndex);
      } catch (Exception e) {
        LOG.error(e.getMessage(), e);
      }
    }

    // Return false to allow the visit to continue
    return false;
  }
Exemplo n.º 2
0
  @Override
  public boolean visitTree(VisitContext context, VisitCallback callback) {
    if (!isVisitable(context)) {
      return false;
    }

    FacesContext facesContext = context.getFacesContext();
    pushComponentToEL(facesContext, null);

    try {
      VisitResult result = context.invokeVisitCallback(this, callback);

      if (result == VisitResult.COMPLETE) {
        return true;
      }

      if (result == VisitResult.ACCEPT) {
        if (context instanceof ExtendedVisitContext) {
          ExtendedVisitContext extendedVisitContext = (ExtendedVisitContext) context;
          if (extendedVisitContext.getVisitMode() == ExtendedVisitContextMode.RENDER) {

            result =
                extendedVisitContext.invokeMetaComponentVisitCallback(
                    this, callback, ACTIVE_ITEM_META_COMPONENT);
            if (result == VisitResult.COMPLETE) {
              return true;
            }
          }
        }
      }

      if (result == VisitResult.ACCEPT) {
        Iterator<UIComponent> kids = this.getFacetsAndChildren();

        while (kids.hasNext()) {
          boolean done = kids.next().visitTree(context, callback);

          if (done) {
            return true;
          }
        }
      }
    } finally {
      popComponentFromEL(facesContext);
    }

    return false;
  }
Exemplo n.º 3
0
  /** @see UIComponent#visitTree */
  @Override
  public boolean visitTree(VisitContext context, VisitCallback callback) {

    // NamingContainers can optimize partial tree visits by taking advantage
    // of the fact that it is possible to detect whether any ids to visit
    // exist underneath the NamingContainer.  If no such ids exist, there
    // is no need to visit the subtree under the NamingContainer.

    // UIForm is a bit different from other NamingContainers.  It only acts
    // as a NamingContainer when prependId is true.  Note that if it
    // weren't for this, we could push this implementation up in to
    // UIComponent and share it across all NamingContainers.  Instead,
    // we currently duplicate this implementation in UIForm and
    // UINamingContainer, so that we can check isPrependId() here.

    if (!this.isPrependId()) {
      return super.visitTree(context, callback);
    }

    Collection<String> idsToVisit = context.getSubtreeIdsToVisit(this);
    assert (idsToVisit != null);

    // If we have ids to visit, let the superclass implementation
    // handle the visit
    if (!idsToVisit.isEmpty()) {
      return super.visitTree(context, callback);
    }

    // If we have no child ids to visit, just visit ourselves, if
    // we are visitable.
    if (isVisitable(context)) {
      FacesContext facesContext = context.getFacesContext();
      pushComponentToEL(facesContext, null);

      try {
        VisitResult result = context.invokeVisitCallback(this, callback);
        return (result == VisitResult.COMPLETE);
      } finally {
        popComponentFromEL(facesContext);
      }
    }

    // Done visiting this subtree.  Return false to allow
    // visit to continue.
    return false;
  }
  protected boolean visitDataChildren(VisitContext visitContext, VisitCallback callback) {
    int rowIndex = 0;

    for (setRowIndex(rowIndex); isRowAvailable(); setRowIndex(++rowIndex)) {
      VisitResult result = visitContext.invokeVisitCallback(this, callback);

      if (result == VisitResult.COMPLETE) {
        return true;
      }

      if (result == VisitResult.REJECT) {
        continue;
      }

      for (UIComponent child : getChildren()) {
        if (child.visitTree(visitContext, callback)) {
          return true;
        }
      }
    }

    return false;
  }