1 package org.exoplatform.portal.faces.application; 2 3 import java.io.IOException ; 4 import java.io.PrintWriter ; 5 import java.util.Locale ; 6 import javax.faces.FacesException; 7 import javax.faces.application.StateManager; 8 import javax.faces.application.ViewHandler; 9 import javax.faces.component.UIComponent; 10 import javax.faces.component.UIViewRoot; 11 import javax.faces.context.FacesContext; 12 import javax.servlet.http.HttpServletResponse ; 13 import org.exoplatform.container.SessionContainer; 14 import org.exoplatform.faces.context.HtmlResponseWriter; 15 import org.exoplatform.portal.faces.component.UIPortal; 16 import org.exoplatform.portal.session.PortalResources; 17 import org.exoplatform.portal.session.ExoPortal ; 18 19 public class ExoPortalViewHandler extends ViewHandler { 20 private ViewHandler implViewHandler_ ; 21 22 public ExoPortalViewHandler(ViewHandler impl) { 23 implViewHandler_ = impl ; 24 } 25 26 public Locale calculateLocale(FacesContext context) { 27 return implViewHandler_.calculateLocale(context) ; 28 } 29 30 public String calculateRenderKitId(FacesContext context) { 31 return implViewHandler_.calculateRenderKitId(context); 32 } 33 34 public UIViewRoot createView(FacesContext context, String viewId) { 35 UIViewRoot uiRoot = implViewHandler_.createView(context, viewId); 36 SessionContainer scontainer = SessionContainer.getInstance() ; 37 UIPortal uiPortal = (UIPortal) scontainer.getComponentInstanceOfType(ExoPortal.class) ; 38 uiRoot.getChildren().add(uiPortal) ; 39 return uiRoot ; 40 } 41 42 public String getActionURL(FacesContext context, String viewId) { 43 return implViewHandler_.getActionURL(context, viewId) ; 44 } 45 46 public String getResourceURL(FacesContext context, String path) { 47 return implViewHandler_.getResourceURL(context, path) ; 48 } 49 50 51 public void renderView(FacesContext context, UIViewRoot viewToRender) 52 throws IOException , FacesException { 53 HttpServletResponse res = 55 (HttpServletResponse )context.getExternalContext().getResponse() ; 56 PortalResources appres = 57 (PortalResources)SessionContainer.getComponent(PortalResources.class); 58 appres.getLocaleConfig().setOutput(res) ; 59 PrintWriter writer = res.getWriter() ; 60 HtmlResponseWriter responseWriter = new HtmlResponseWriter(writer) ; 61 context.setResponseWriter(responseWriter) ; 62 UIComponent uiPortal = (UIComponent)viewToRender.getChildren().get(0); 63 uiPortal.encodeChildren(context) ; 64 StateManager smanager = context.getApplication().getStateManager() ; 65 smanager.saveSerializedView(context) ; 66 responseWriter.flush() ; 67 } 68 69 public UIViewRoot restoreView(FacesContext context, String viewId) { 70 return implViewHandler_.restoreView(context, viewId) ; 71 } 72 73 public void writeState(FacesContext context) throws IOException { 74 implViewHandler_.writeState(context) ; 75 } 76 } 77 | Popular Tags |