if (rawState == null) {
return null;
}
final Map<String, Object> state = (Map<String, Object>) rawState[1];
final StateContext stateContext = StateContext.getStateContext(context);
if (state != null) {
try {
stateContext.setTrackViewModifications(false);
context.getAttributes().put(SKIP_ITERATION_HINT, true);
Set<VisitHint> hints = EnumSet.of(VisitHint.SKIP_ITERATION, VisitHint.EXECUTE_LIFECYCLE);
VisitContext visitContext = VisitContext.createVisitContext(context, null, hints);
viewRoot.visitTree(visitContext, new VisitCallback() {
public VisitResult visit(VisitContext context, UIComponent target) {
VisitResult result = VisitResult.ACCEPT;
String cid = target.getClientId(context.getFacesContext());
Object stateObj = state.get(cid);
if (stateObj != null && !stateContext.componentAddedDynamically(target)) {
boolean restoreStateNow = true;
if (stateObj instanceof StateHolderSaver) {
restoreStateNow = !((StateHolderSaver) stateObj).componentAddedDynamically();
}
if (restoreStateNow) {
try {
target.restoreState(context.getFacesContext(), stateObj);
} catch (Exception e) {
String msg =
MessageUtils.getExceptionMessageString(
MessageUtils.PARTIAL_STATE_ERROR_RESTORING_ID,
cid,
e.toString());
throw new FacesException(msg, e);
}
}
}
return result;
}
});
restoreDynamicActions(context, stateContext, state);
} finally {
stateContext.setTrackViewModifications(true);
context.getAttributes().remove(SKIP_ITERATION_HINT);
}
} else {
viewRoot = null;
}