}
}
else
{
// Per the spec: build the view.
ViewDeclarationLanguage vdl = _vdlFactory.getViewDeclarationLanguage(viewId);
Object faceletViewState = null;
try
{
ViewMetadata metadata = vdl.getViewMetadata (context, viewId);
if (metadata != null)
{
view = metadata.createMetadataView(context);
// If no view and response complete there is no need to continue
if (view == null && context.getResponseComplete())
{
return null;
}
}
if (view == null)
{
view = context.getApplication().getViewHandler().createView(context, viewId);
}
context.setViewRoot (view);
boolean skipBuildView = false;
if (state != null && state[1] != null)
{
// Since JSF 2.2, UIViewRoot.restoreViewScopeState() must be called, but
// to get the state of the root, it is necessary to force calculate the
// id from this location. Remember in this point, PSS is enabled, so the
// code match with the assigment done in
// FaceletViewDeclarationLanguage.buildView()
states = (Map<String, Object>) state[1];
faceletViewState = UIComponentBase.restoreAttachedState(
context,states.get(ComponentSupport.FACELET_STATE_INSTANCE));
if (faceletViewState != null && _viewPoolProcessor != null)
{
ViewPool viewPool = _viewPoolProcessor.getViewPool(context, view);
if (viewPool != null)
{
ViewStructureMetadata viewMetadata = viewPool.retrieveDynamicViewStructureMetadata(
context, view, (FaceletState) faceletViewState);
if (viewMetadata != null)
{
ViewEntry entry = viewPool.popDynamicStructureView(context, view,
(FaceletState) faceletViewState);
if (entry != null)
{
skipBuildView = true;
_viewPoolProcessor.cloneAndRestoreView(context, view, entry, viewMetadata);
}
}
}
}
if (view.getId() == null)
{
view.setId(view.createUniqueId(context, null));
}
if (faceletViewState != null)
{
view.getAttributes().put(ComponentSupport.FACELET_STATE_INSTANCE, faceletViewState);
}
if (state.length == 3)
{
//Jump to where the count is
view.getAttributes().put(UNIQUE_ID_COUNTER_KEY, state[2]);
}
Object viewRootState = states.get(view.getClientId(context));
if (viewRootState != null)
{
try
{
view.pushComponentToEL(context, view);
view.restoreViewScopeState(context, viewRootState);
}
finally
{
view.popComponentFromEL(context);
}
}
}
// On RestoreViewExecutor, setProcessingEvents is called first to false
// and then to true when postback. Since we need listeners registered to PostAddToViewEvent
// event to be handled, we should enable it again. For partial state saving we need this listeners
// be called from here and relocate components properly.
if (!skipBuildView)
{
try
{
context.setProcessingEvents (true);
vdl.buildView (context, view);
// In the latest code related to PostAddToView, it is
// triggered no matter if it is applied on postback. It seems that MYFACES-2389,
// TRINIDAD-1670 and TRINIDAD-1671 are related.
suscribeListeners(view);
}