code: private void clearTransientAndNonFaceletComponents(final FacesContext context, final UIComponent component)
      {
          //Scan children
          int childCount = component.getChildCount();
          if (childCount > 0)
          {
              for (int i = 0; i < childCount; i++)
              {
                  UIComponent child = component.getChildren().get(i);
                  if (child != null && child.isTransient() &&
                      child.getAttributes().get(ComponentSupport.MARK_CREATED) == null)
                  {
                      component.getChildren().remove(i);
                      i--;
                      childCount--;
                  }
                  else
                  {
                      if (child.getChildCount() > 0 || !child.getFacets().isEmpty())
                      {
                          clearTransientAndNonFaceletComponents(context, child);
                      }
                  }
              }
          }
  
          //Scan facets
          if (component.getFacetCount() > 0)
          {
              Map<String, UIComponent> facets = component.getFacets();
              for (Iterator<UIComponent> itr = facets.values().iterator(); itr.hasNext();)
              {
                  UIComponent fc = itr.next();
                  if (fc != null && fc.isTransient() &&
                      fc.getAttributes().get(ComponentSupport.MARK_CREATED) == null)
                  {
                      itr.remove();
                  }
                  else
                  {
                      if (fc.getChildCount() > 0 || !fc.getFacets().isEmpty())
                      {
                          clearTransientAndNonFaceletComponents(context, fc);
                      }
                  }
              }
          }
      }
docs: Clear all transient components not created by facelets algorithm. In this way,
  we ensure the component tree does not have any changes done after markInitialState.
  
  @param context
  @param component