* @throws IOException if an error occurs building the view.
*/
@Override
public void buildView(FacesContext ctx, UIViewRoot view)
throws IOException {
StateContext stateCtx = StateContext.getStateContext(ctx);
if (Util.isViewPopulated(ctx, view)) {
Facelet f = faceletFactory.getFacelet(view.getViewId());
// Disable events from being intercepted by the StateContext by
// virute of re-applying the handlers.
try {
stateCtx.setTrackViewModifications(false);
f.apply(ctx, view);
reapplyDynamicActions(ctx);
if (stateCtx.isPartialStateSaving(ctx, view.getViewId())) {
markInitialStateIfNotMarked(view);
}
} finally {
stateCtx.setTrackViewModifications(true);
}
return;
}
view.setViewId(view.getViewId());
if (LOGGER.isLoggable(Level.FINE)) {
LOGGER.fine("Building View: " + view.getViewId());
}
if (faceletFactory == null) {
ApplicationAssociate associate = ApplicationAssociate.getInstance(ctx.getExternalContext());
faceletFactory = associate.getFaceletFactory();
assert (faceletFactory != null);
}
RequestStateManager.set(ctx,
RequestStateManager.FACELET_FACTORY,
faceletFactory);
Facelet f = faceletFactory.getFacelet(view.getViewId());
// populate UIViewRoot
try {
ctx.getAttributes().put(IS_BUILDING_INITIAL_STATE, Boolean.TRUE);
stateCtx.setTrackViewModifications(false);
f.apply(ctx, view);
if (f instanceof XMLFrontMatterSaver) {
XMLFrontMatterSaver frontMatterSaver = (XMLFrontMatterSaver) f;
String DOCTYPE = frontMatterSaver.getSavedDoctype();
if (null != DOCTYPE) {
Util.saveDOCTYPEToFacesContextAttributes(DOCTYPE);
}
String XMLDECL = frontMatterSaver.getSavedXMLDecl();
if (null != XMLDECL) {
Util.saveXMLDECLToFacesContextAttributes(XMLDECL);
}
}
if (!stateCtx.isPartialStateSaving(ctx, view.getViewId())) {
reapplyDynamicActions(ctx);
}
doPostBuildActions(ctx, view);
} finally {