}
// Create a FacesContext for this request if necessary
LifecycleFactory lf = (LifecycleFactory)
FactoryFinder.getFactory(FactoryFinder.LIFECYCLE_FACTORY);
Lifecycle lifecycle = // FIXME - alternative lifecycle ids
lf.getLifecycle(LifecycleFactory.DEFAULT_LIFECYCLE);
boolean created = false;
FacesContext context = FacesContext.getCurrentInstance();
if (context == null) {
if (log.isTraceEnabled()) {
log.trace(" Creating new FacesContext for '" + uri + "'");
}
created = true;
FacesContextFactory fcf = (FacesContextFactory)
FactoryFinder.getFactory(FactoryFinder.FACES_CONTEXT_FACTORY);
context = fcf.getFacesContext(servlet.getServletContext(),
request, response, lifecycle);
}
// Create a new view root
ViewHandler vh = context.getApplication().getViewHandler();
if (log.isTraceEnabled()) {
log.trace(" Creating new view for '" + uri + "'");
}
context.setViewRoot(vh.createView(context, uri));
// Cause the view to be rendered
if (log.isTraceEnabled()) {
log.trace(" Rendering view for '" + uri + "'");
}
try {
lifecycle.render(context);
} finally {
if (created) {
if (log.isTraceEnabled()) {
log.trace(" Releasing context for '" + uri + "'");
}