// use the locale from the previous view if is was one which will be
// the case if this is called from NavigationHandler. There wouldn't be
// one for the initial case.
if (context.getViewRoot() != null) {
UIViewRoot oldViewRoot = context.getViewRoot();
LayoutDefinition oldLD = ViewRootUtil.getLayoutDefinition(oldViewRoot);
if ((oldLD != null) && oldViewRoot.getViewId().equals(viewId)) {
// If you navigate to the page you are already on, JSF will
// re-create the UIViewRoot of the current page. The initPage
// event needs to be reset so that it will re-execute itself.
oldLD.setInitPageExecuted(context, Boolean.FALSE);
}
locale = context.getViewRoot().getLocale();
renderKitId = context.getViewRoot().getRenderKitId();
}
// Create the ViewRoot
UIViewRoot viewRoot = _oldViewHandler.createView(context, viewId);
viewRoot.setViewId(viewId);
ViewRootUtil.setLayoutDefinitionKey(viewRoot, viewId);
// if there was no locale from the previous view, calculate the locale
// for this view.
if (locale == null) {
locale = calculateLocale(context);
}
viewRoot.setLocale(locale);
// set the renderkit
if (renderKitId == null) {
renderKitId = calculateRenderKitId(context);
}
viewRoot.setRenderKitId(renderKitId);
// Save the current viewRoot, temporarily set the new UIViewRoot so
// beforeCreate, afterCreate will function correctly
UIViewRoot currentViewRoot = context.getViewRoot();
// Set the View Root to the new viewRoot
// NOTE: This must happen after return _oldViewHandler.createView(...)
// NOTE2: However, we really want the UIViewRoot available during
// initPage events which are fired during
// getLayoutDefinition()... so we need to set this, then unset
// it if we go through _oldViewHandler.createView(...)
context.setViewRoot(viewRoot);
// Initialize Resources / Create Tree
LayoutDefinition def = null;
try {
def = ViewRootUtil.getLayoutDefinition(viewRoot);
} catch (LayoutDefinitionException ex) {
if (LogUtil.configEnabled()) {
LogUtil.config("JSFT0005", (Object) viewId);
if (LogUtil.finestEnabled()) {
LogUtil.finest(
"File (" + viewId + ") not found!", ex);
}
}
// Restore original ViewRoot, we set it prematurely
if (currentViewRoot != null) {
// FIXME: Talk to Ryan about restoring the ViewRoot to null!!
context.setViewRoot(currentViewRoot);
}
// FIXME: Provide better feedback when no .jsf & no .jsp
// FIXME: Difficult to tell at this stage if no .jsp is present
// Not found, delegate to old ViewHandler
return _oldViewHandler.createView(context, viewId);
} catch (RuntimeException ex) {
// Restore original ViewRoot, we set it prematurely
if (currentViewRoot != null) {
// FIXME: Talk to Ryan about restoring the ViewRoot to null!!
context.setViewRoot(currentViewRoot);
}
// Allow error to be thrown (this isn't the normal code path)
throw ex;
}
// We need to do this again b/c an initPage handler may have changed
// the viewRoot
viewRoot = context.getViewRoot();
// Check to make sure we found a LD and that the response isn't
// already finished (initPage could complete the response...
// i.e. during a redirect).
if ((def != null) && !context.getResponseComplete()) {
// Ensure that our Resources are available
Iterator<Resource> it = def.getResources().iterator();
Resource resource = null;
while (it.hasNext()) {
resource = it.next();
// Just calling getResource() puts it in the Request scope
resource.getFactory().getResource(context, resource);