示例#1
0
  public UIComponent findCompositeComponentUsingLocation(FacesContext ctx, Location location) {

    StackHandler sh = getStackHandler(StackType.TreeCreation);
    Stack<UIComponent> s = sh.getStack(false);
    if (s != null) {
      String path = location.getPath();
      for (int i = s.size(); i > 0; i--) {
        UIComponent cc = s.get(i - 1);
        Resource r = (Resource) cc.getAttributes().get(Resource.COMPONENT_RESOURCE_KEY);
        if (path.endsWith('/' + r.getResourceName()) && path.contains(r.getLibraryName())) {
          return cc;
        }
      }
    } else {
      // runtime eval
      String path = location.getPath();
      UIComponent cc = UIComponent.getCurrentCompositeComponent(ctx);
      while (cc != null) {
        Resource r = (Resource) cc.getAttributes().get(Resource.COMPONENT_RESOURCE_KEY);
        if (path.endsWith('/' + r.getResourceName()) && path.contains(r.getLibraryName())) {
          return cc;
        }
        cc = UIComponent.getCompositeComponentParent(cc);
      }
    }

    // we could not find the composite component because the location was not found,
    // this will happen if the #{cc} refers to a composite component one level up,
    // so we are going after the current composite component.
    //
    return UIComponent.getCurrentCompositeComponent(ctx);
  }
示例#2
0
  public String getIsCompositeComponentValue() {
    String result = null;

    UIComponent currentComposite =
        UIComponent.getCurrentCompositeComponent(FacesContext.getCurrentInstance());
    result = "" + UIComponent.isCompositeComponent(currentComposite);

    return result;
  }
示例#3
0
  public void apply(FaceletContext ctx, UIComponent parent) throws IOException {

    UIComponent compositeParent = UIComponent.getCurrentCompositeComponent(ctx.getFacesContext());
    if (compositeParent == null) {
      return;
    }

    boolean required = ((this.required != null) && this.required.getBoolean(ctx));

    if (compositeParent.getChildCount() == 0 && required) {
      throwRequiredException(ctx, compositeParent);
    }

    List<UIComponent> compositeChildren = compositeParent.getChildren();
    List<UIComponent> parentChildren = parent.getChildren();
    parentChildren.addAll(compositeChildren);
  }
示例#4
0
    public boolean push(UIComponent compositeComponent) {

      Stack<UIComponent> tstack = CompositeComponentStackManager.this.treeCreation.getStack(false);
      Stack<UIComponent> stack = getStack(false);
      UIComponent ccp;
      if (tstack != null) {
        // We have access to the stack of composite components
        // the tree creation process has made available.
        // Since we can' reliably access the parent composite component
        // of the current composite component, use the index of the
        // current composite component within the stack to locate the
        // parent.
        ccp = compositeComponent;
      } else {
        // no tree creation stack available, so use the runtime stack.
        // If the current stack isn't empty, then use the component
        // on the stack as the current composite component.
        stack = getStack(false);

        if (compositeComponent == null) {
          if (stack != null && !stack.isEmpty()) {
            ccp = getCompositeParent(stack.peek());
          } else {
            ccp =
                getCompositeParent(
                    (UIComponent.getCurrentCompositeComponent(FacesContext.getCurrentInstance())));
          }
        } else {
          ccp = compositeComponent;
        }
      }

      if (ccp != null) {
        if (stack == null) {
          stack = getStack(true);
        }
        stack.push(ccp);
        return true;
      }
      return false;
    }