コード例 #1
0
  public UIComponent createComponent(FaceletContext ctx) {

    FacesContext context = ctx.getFacesContext();
    UIComponent cc;
    // we have to handle the binding here, as Application doesn't
    // expose a method to do so with Resource.
    if (binding != null) {
      ValueExpression ve = binding.getValueExpression(ctx, UIComponent.class);
      cc = (UIComponent) ve.getValue(ctx);
      if (cc != null && !UIComponent.isCompositeComponent(cc)) {
        if (LOGGER.isLoggable(Level.SEVERE)) {
          LOGGER.log(Level.SEVERE, "jsf.compcomp.binding.eval.non.compcomp", binding.toString());
        }
        cc = null;
      }
      if (cc == null) {
        cc = context.getApplication().createComponent(context, ccResource);
        ve.setValue(ctx, cc);
      }
    } else {
      cc = context.getApplication().createComponent(context, ccResource);
    }
    setCompositeComponent(context, cc);

    return cc;
  }
コード例 #2
0
ファイル: TestBean.java プロジェクト: codylerum/mojarra
  public String getIsCompositeComponentValue() {
    String result = null;

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

    return result;
  }
コード例 #3
0
    public boolean push(UIComponent compositeComponent) {

      if (compositeComponent != null) {
        assert (UIComponent.isCompositeComponent(compositeComponent));
        Stack<UIComponent> s = getStack(true);
        s.push(compositeComponent);
        return true;
      }
      return false;
    }
コード例 #4
0
  protected boolean pushComponentToEL(
      FaceletContext ctx, UIComponent c, CompositeComponentStackManager ccStackManager) {

    c.pushComponentToEL(ctx.getFacesContext(), c);
    boolean compcompPushed = false;

    if (UIComponent.isCompositeComponent(c)) {
      compcompPushed = ccStackManager.push(c, TreeCreation);
    }
    return compcompPushed;
  }
コード例 #5
0
  public void apply(FaceletContext ctx, UIComponent parent) throws IOException {

    // only process if it's been created
    if (parent == null || !ComponentHandler.isNew(parent)) {
      return;
    }

    if (isEventSource(parent)) {
      applyAttachedObject(ctx.getFacesContext(), parent);
    } else if (UIComponent.isCompositeComponent(parent)) {
      // Allow the composite component to know about the target component.
      TagHandlerUtils.getOrCreateRetargetableHandlersList(parent).add(this);
    } else {
      throw new TagException(
          this.tag, "Parent does not match event source requirements: " + parent);
    }
  }
コード例 #6
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);
    }
  }
コード例 #7
0
      public void applyMetadata(FaceletContext ctx, Object instance) {

        ValueExpression ve = attr.getValueExpression(ctx, type);
        UIComponent cc = (UIComponent) instance;
        assert (UIComponent.isCompositeComponent(cc));
        Map<String, Object> attrs = cc.getAttributes();
        BeanInfo componentMetadata = (BeanInfo) attrs.get(UIComponent.BEANINFO_KEY);
        BeanDescriptor desc = componentMetadata.getBeanDescriptor();
        Collection<String> attributesWithDeclaredDefaultValues =
            (Collection<String>) desc.getValue(RIConstants.ATTRS_WITH_DECLARED_DEFAULT_VALUES);
        if (null != attributesWithDeclaredDefaultValues
            && attributesWithDeclaredDefaultValues.contains(name)) {
          // It is necessary to remove the value from the attribute
          // map because the ELexpression transparancy doesn't know
          // about the value's existence.
          attrs.remove(name);
        }
        cc.setValueExpression(name, ve);
      }
コード例 #8
0
  public void broadcast(FacesContext context) throws AbortProcessingException {
    // Set up the correct context and fire our wrapped event
    UIDataAdaptor dataAdaptor = getComponent();
    initialRowKey = dataAdaptor.getRowKey();

    UIComponent compositeParent = null;

    UIComponent targetComponent = event.getComponent();

    try {
      if (!UIComponent.isCompositeComponent(targetComponent)) {
        compositeParent = UIComponent.getCompositeComponentParent(targetComponent);
      }

      if (compositeParent != null) {
        compositeParent.pushComponentToEL(context, null);
      }

      setupEventContext(context);

      targetComponent.pushComponentToEL(context, null);
      targetComponent.broadcast(event);
    } finally {
      try {
        dataAdaptor.setRowKey(context, initialRowKey);
      } catch (Exception e) {
        LOGGER.error(e.getMessage(), e);
      }

      initialRowKey = null;

      targetComponent.popComponentFromEL(context);

      if (compositeParent != null) {
        compositeParent.popComponentFromEL(context);
      }
    }
  }
コード例 #9
0
  /**
   * Method handles UIComponent tree creation in accordance with the JSF 1.2 spec.
   *
   * <ol>
   *   <li>First determines this UIComponent's id by calling {@link
   *       javax.faces.view.facelets.ComponentHandler#getTagId()}.
   *   <li>Search the parent for an existing UIComponent of the id we just grabbed
   *   <li>If found, {@link
   *       com.sun.faces.facelets.tag.jsf.ComponentSupport#markForDeletion(javax.faces.component.UIComponent)
   *       mark} its children for deletion.
   *   <li>If <i>not</i> found, call {@link #createComponent(FaceletContext) createComponent}.
   *       <ol>
   *         <li>Only here do we apply {@link
   *             com.sun.faces.facelets.tag.MetaTagHandlerImpl#setAttributes(FaceletContext,
   *             Object)}
   *         <li>Set the UIComponent's id
   *         <li>Set the RendererType of this instance
   *       </ol>
   *   <li>Now apply the nextHandler, passing the UIComponent we've created/found.
   *   <li>Now add the UIComponent to the passed parent
   *   <li>Lastly, if the UIComponent already existed (found), then {@link
   *       ComponentSupport#finalizeForDeletion(UIComponent) finalize} for deletion.
   * </ol>
   *
   * @throws TagException if the UIComponent parent is null
   */
  @Override
  public void apply(FaceletContext ctx, UIComponent parent) throws IOException {
    FacesContext context = ctx.getFacesContext();

    // make sure our parent is not null
    if (parent == null) {
      throw new TagException(owner.getTag(), "Parent UIComponent was null");
    }

    // our id
    String id = ctx.generateUniqueId(owner.getTagId());

    // grab our component
    UIComponent c = findChild(ctx, parent, id);
    if (null == c
        && context.isPostback()
        && UIComponent.isCompositeComponent(parent)
        && parent.getAttributes().get(id) != null) {
      c = findReparentedComponent(ctx, parent, id);
    } else {
      /**
       * If we found a child that is dynamic, the actual parent might have changed, so we need to
       * remove it from the actual parent. The reapplyDynamicActions will then replay the actions
       * and will make sure it ends up in the correct order.
       */
      if (c != null
          && c.getParent() != parent
          && c.getAttributes().containsKey(DYNAMIC_COMPONENT)) {
        c.getParent().getChildren().remove(c);
      }
    }

    boolean componentFound = false;
    if (c != null) {
      componentFound = true;
      doExistingComponentActions(ctx, id, c);
    } else {
      c = this.createComponent(ctx);

      doNewComponentActions(ctx, id, c);
      assignUniqueId(ctx, parent, id, c);

      // hook method
      owner.onComponentCreated(ctx, c, parent);
    }

    CompositeComponentStackManager ccStackManager =
        CompositeComponentStackManager.getManager(context);
    boolean compcompPushed = pushComponentToEL(ctx, c, ccStackManager);

    if (ProjectStage.Development == context.getApplication().getProjectStage()) {
      ComponentSupport.setTagForComponent(context, c, this.owner.getTag());
    }

    // If this this a naming container, stop generating unique Ids
    // for the repeated tags
    boolean setUniqueIds = false;
    boolean oldUnique = false;
    if (c instanceof NamingContainer) {
      oldUnique = ComponentSupport.setNeedUniqueIds(ctx, false);
      setUniqueIds = true;
    }
    try {
      // first allow c to get populated
      owner.applyNextHandler(ctx, c);
    } finally {
      if (setUniqueIds) ComponentSupport.setNeedUniqueIds(ctx, oldUnique);
    }

    // finish cleaning up orphaned children
    if (componentFound) {
      doOrphanedChildCleanup(ctx, parent, c);
    }

    this.privateOnComponentPopulated(ctx, c);
    owner.onComponentPopulated(ctx, c, parent);
    // add to the tree afterwards
    // this allows children to determine if it's
    // been part of the tree or not yet
    addComponentToView(ctx, parent, c, componentFound);
    adjustIndexOfDynamicChildren(context, c);
    popComponentFromEL(ctx, c, ccStackManager, compcompPushed);
  }