Пример #1
0
  @Override
  public void applyNextHandler(FaceletContext ctx, UIComponent c)
      throws IOException, FacesException, ELException {

    // attributes need to be applied before any action is taken on
    // nested children handlers or the composite component handlers
    // as there may be an expression evaluated at tree creation time
    // that needs access to these attributes
    setAttributes(ctx, c);

    // Allow any nested elements that reside inside the markup element
    // for this tag to get applied
    super.applyNextHandler(ctx, c);

    // Apply the facelet for this composite component
    applyCompositeComponent(ctx, c);

    // Allow any PDL declared attached objects to be retargeted
    if (ComponentHandler.isNew(c)) {
      FacesContext context = ctx.getFacesContext();
      String viewId = context.getViewRoot().getViewId();
      // PENDING(rlubke): performance
      ViewDeclarationLanguageFactory factory =
          (ViewDeclarationLanguageFactory)
              FactoryFinder.getFactory(FactoryFinder.VIEW_DECLARATION_LANGUAGE_FACTORY);

      ViewDeclarationLanguage vdl = factory.getViewDeclarationLanguage(viewId);
      vdl.retargetAttachedObjects(context, c, getAttachedObjectHandlers(c, false));
      vdl.retargetMethodExpressions(context, c);

      // RELEASE_PENDING This is *ugly*.  See my comments in
      // ComponentTagHandlerDelegateImpl at the end of the apply()
      // method
      if (StateContext.getStateContext(context).partialStateSaving(context, viewId)) {
        markInitialState(c);
      }
    }
  }
Пример #2
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);
  }