throws IOException {
FacesContext facesContext = FacesContext.getCurrentInstance();
if (null != facesContext) {
Lifecycle facesLifecycle = getFacesLifecycle();
PhaseListener[] phaseListeners = facesLifecycle.getPhaseListeners();
PhaseEvent restoreViewEvent = new PhaseEvent(facesContext,
PhaseId.RESTORE_VIEW, this);
processPhaseListeners(phaseListeners, restoreViewEvent, true);
// Fix for a http://jira.jboss.org/jira/browse/RF-1056
if (facesContext.getResponseComplete()) {
return;
}
// fix for a http://jira.jboss.com/jira/browse/RF-1064 .
// viewRoot can be created outside.
UIViewRoot savedViewRoot = facesContext.getViewRoot();
try {
// create "dummy" viewRoot, to avoid problems in phase listeners.
UIViewRoot root = new UIViewRoot();
String key = resource.getKey();
if (null != key && !key.startsWith("/")) {
key = "/" + key;
}
root.setViewId(key);
root.setLocale(Locale.getDefault());
root.setRenderKitId(RenderKitFactory.HTML_BASIC_RENDER_KIT);
facesContext.setViewRoot(root);
// Invoke after restore view phase listeners
processPhaseListeners(phaseListeners, restoreViewEvent, false);
// Fix for a http://jira.jboss.org/jira/browse/RF-1056
if (!facesContext.getResponseComplete()) {
// Invoke before render view phase listeners
PhaseEvent renderViewEvent = new PhaseEvent(facesContext,
PhaseId.RENDER_RESPONSE, this);
processPhaseListeners(phaseListeners, renderViewEvent, true);
sendResource(resourceContext, resource);
processPhaseListeners(phaseListeners, renderViewEvent, false);
}