FacesContext context = null;
try
{
// Get the FacesContext instance for this request
Lifecycle lifecycle = getLifecycle();
context =
getFacesContextFactory().getFacesContext(mPortletConfig, request, response, lifecycle);
ExternalContext extCtx = context.getExternalContext();
// Use request from ExternalContext in case its been wrapped by an
// extension
RenderRequest extRequest = (RenderRequest) extCtx.getRequest();
scopeId = extRequest.getParameter(REQUEST_SCOPE_ID_RENDER_PARAM);
if (restoreBridgeRequestScopeData(context, scopeId))
{
// Because the Bridge is required to always save/restore the
// VIEW_STATE
// parameter -- always attempt a restore
extRequest = restoreActionParams(context);
// only restores if first render after action
// afterwards not restored from Bridge request scope
// rather its saved/restored by Faces.
restoreFacesView(context, scopeId);
}
// Ensure the ContentType is set before rendering
if (extCtx.getResponseContentType() == null)
{
response.setContentType(extRequest.getResponseContentType());
}
// ensure that isPostback attribute set if VIEW_STATE param exists
if (extCtx.getRequestParameterValuesMap().containsKey(ResponseStateManager.VIEW_STATE_PARAM))
{
extCtx.getRequestMap().put(Bridge.IS_POSTBACK_ATTRIBUTE, Boolean.TRUE);
}
// Note: if the scope wasn't restored then the Faces
// FACES_VIEW_STATE
// parameter will not have been carried into this render and hence
// default Faces impls will not see this render as occuring in a
// in a postback (isPostback() will return false. This means Faces
// will create a new Tree instead of restoring one -- the semantics
// one should get if the Bridge can't access its requestScope.
// if the requestScope restored the ViewRoot then this must be
// the first render after the action -- hence the tree isn't yet
// stored/managed by Faces -- we can merely render it
if (context.getViewRoot() == null)
{
// add self as PhaseListener to prevent action phases from
// executing
lifecycle.addPhaseListener(this);
try
{
lifecycle.execute(context);
}
catch (Exception e)
{
// When exception occurs remove stored scope so don't
// get stuck replaying the error when/if user refreshes
if (scopeId != null)
{
removeRequestScopes(scopeId);
}
}
finally
{
lifecycle.removePhaseListener(this);
}
}
getLifecycle().render(context);
// When we have navigated to this view between the action and render