viewRoot.visitTree(visitContext, new VisitCallback() {
public VisitResult visit(VisitContext context, UIComponent target) {
VisitResult result = VisitResult.ACCEPT;
Object stateObj;
if (!target.isTransient()) {
if (stateContext.componentAddedDynamically(target)) {
target.getAttributes().put(DYNAMIC_COMPONENT,
new Integer(target.getParent().getChildren().indexOf(target)));
stateObj = new StateHolderSaver(finalContext, target);
} else {
stateObj = target.saveState(context.getFacesContext());