示例#1
0
    private void handleAddEvent(FacesContext context, PostAddToViewEvent event) {

      // if the root is transient, then no action is ever needed here
      if (context.getViewRoot().isTransient()) {
        return;
      }

      UIComponent added = event.getComponent();
      if (added.isTransient() || added instanceof UIViewRoot) {
        return;
      }

      // this component, while not transient may be a child or facet
      // of component that is.  We'll have to search the parent hierarchy
      // to the root to confirm.
      UIComponent parent = added.getParent();
      while (parent != null) {
        if (parent.isTransient()) {
          return;
        }
        parent = parent.getParent();
      }

      parent = added.getParent();
      if (dynamicAdds == null) {
        dynamicAdds = new LinkedHashMap<String, ComponentStruct>();
      }
      ComponentStruct toAdd = new ComponentStruct();

      toAdd.clientId = added.getClientId(context);
      toAdd.parentClientId = parent.getClientId(context);
      // this needs work
      int idx = parent.getChildren().indexOf(added);
      if (idx == -1) {
        // this must be a facet
        for (Map.Entry<String, UIComponent> facet : parent.getFacets().entrySet()) {
          if (facet.getValue() == added) {
            toAdd.facetName = facet.getKey();
            break;
          }
        }
      } else {
        toAdd.indexOfChildInParent = parent.getChildren().indexOf(added);
      }
      if (dynamicRemoves != null) {
        dynamicRemoves.remove(toAdd.clientId);
      }
      added.getAttributes().put(DYNAMIC_COMPONENT, Boolean.TRUE);
      dynamicAdds.put(toAdd.clientId, toAdd);
    }
示例#2
0
 private boolean hasTransientAncestor(UIComponent component) {
   UIComponent parent = component.getParent();
   while (parent != null) {
     if (parent.isTransient()) {
       return true;
     }
     parent = parent.getParent();
   }
   return false;
 }
示例#3
0
 /**
  * Handle the remove.
  *
  * @param context the Faces context.
  * @param component the UI component to add to the list as a REMOVE.
  */
 private void handleRemove(FacesContext context, UIComponent component) {
   if (!component.isTransient() && !hasTransientAncestor(component)) {
     if (component.isInView()) {
       decrementDynamicChildCount(component.getParent());
       ComponentStruct struct = new ComponentStruct();
       struct.action = ComponentStruct.REMOVE;
       struct.clientId = component.getClientId(context);
       struct.id = component.getId();
       handleAddRemoveWithAutoPrune(component, struct);
     }
   }
 }
示例#4
0
    /**
     * Handle the add.
     *
     * @param context the Faces context.
     * @param component the UI component to add to the list as an ADD.
     */
    private void handleAdd(FacesContext context, UIComponent component) {
      if (!component.isTransient() && !hasTransientAncestor(component)) {
        if (component.getParent() != null && component.getParent().isInView()) {
          String id = component.getId();

          /*
           * Since adding a component, can mean you are really reparenting
           * it, we need to make sure the OLD clientId is not cached, we do
           * that by setting the id.
           */
          if (id != null) {
            component.setId(id);
          }

          if (component.getParent().getFacets().containsValue(component)) {
            Map facets = component.getParent().getFacets();
            Iterator entries = facets.entrySet().iterator();
            while (entries.hasNext()) {
              Map.Entry entry = (Map.Entry) entries.next();
              if (entry.getValue() == component) {
                incrementDynamicChildCount(component.getParent());
                component.clearInitialState();
                component
                    .getAttributes()
                    .put(DYNAMIC_COMPONENT, component.getParent().getChildren().indexOf(component));
                ComponentStruct struct = new ComponentStruct();
                struct.action = ComponentStruct.ADD;
                struct.facetName = entry.getKey().toString();
                struct.parentClientId = component.getParent().getClientId(context);
                struct.clientId = component.getClientId(context);
                struct.id = component.getId();
                handleAddRemoveWithAutoPrune(component, struct);
              }
            }
          } else {
            incrementDynamicChildCount(component.getParent());
            component.clearInitialState();
            component
                .getAttributes()
                .put(DYNAMIC_COMPONENT, component.getParent().getChildren().indexOf(component));
            ComponentStruct struct = new ComponentStruct();
            struct.action = ComponentStruct.ADD;
            struct.parentClientId = component.getParent().getClientId(context);
            struct.clientId = component.getClientId(context);
            struct.id = component.getId();
            handleAddRemoveWithAutoPrune(component, struct);
          }
        }
      }
    }
示例#5
0
    private void handleRemoveEvent(FacesContext context, PreRemoveFromViewEvent event) {

      UIComponent removed = event.getComponent();
      if (removed.isTransient()) {
        return;
      }
      if (dynamicRemoves == null) {
        dynamicRemoves = new ArrayList<String>();
      }
      String clientId = event.getComponent().getClientId(context);
      if (dynamicAdds != null && dynamicAdds.containsKey(clientId)) {
        dynamicAdds.remove(clientId);
      }
      dynamicRemoves.add(clientId);
    }