code: @SuppressWarnings("unchecked")
      private void removeFormerChildren(UIComponent component)
      {
          List<String> formerChildIds = (List<String>)component.getAttributes().get(FORMER_CHILD_IDS_SET_ATTR);
          if (formerChildIds != null)
          {
              for (String childId : formerChildIds)
              {
                  if (_childrenAdded == null || !_childrenAdded.contains(childId))
                  {
                      UIComponent childToRemove = component.findComponent(childId);
                      if (childToRemove != null)
                      {
                          component.getChildren().remove(childToRemove);
                      }
                  }
              }
              if (_childrenAdded == null)
              {
                  component.getAttributes().remove(FORMER_CHILD_IDS_SET_ATTR);
              }
              else
              {
                  component.getAttributes().put(FORMER_CHILD_IDS_SET_ATTR, _childrenAdded);
              }
          }
          else
          {
              if (_childrenAdded != null)
              {
                  component.getAttributes().put(FORMER_CHILD_IDS_SET_ATTR, _childrenAdded);
              }
          }
      }
docs: Remove any child components of the associated components which do not have corresponding tags as children of this
  tag. This only happens when a view is being re-rendered and there are components in the view tree which don't
  have corresponding JSP tags. Wrapping JSF tags in JSTL "c:if" statements is one way this can happen. <br />
  Attention: programmatically added components are are not affected by this: they will not be on the old list of
  created components nor on the new list of created components, so nothing will happen to them.