String facetName = findFacetNameForComponent(component);
if (facetName != null) {
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 = facetName;
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);