1 16 package org.directwebremoting.faces; 17 18 import java.io.IOException ; 19 20 import javax.faces.FactoryFinder; 21 import javax.faces.context.FacesContext; 22 import javax.faces.context.FacesContextFactory; 23 import javax.faces.lifecycle.Lifecycle; 24 import javax.faces.lifecycle.LifecycleFactory; 25 import javax.servlet.Filter ; 26 import javax.servlet.FilterChain ; 27 import javax.servlet.FilterConfig ; 28 import javax.servlet.ServletContext ; 29 import javax.servlet.ServletException ; 30 import javax.servlet.ServletRequest ; 31 import javax.servlet.ServletResponse ; 32 33 import org.directwebremoting.util.Logger; 34 35 42 public class FacesExtensionFilter implements Filter 43 { 44 47 public void init(FilterConfig config) throws ServletException 48 { 49 servletContext = config.getServletContext(); 50 } 51 52 55 public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException , ServletException 56 { 57 FacesContextFactory contextFactory = (FacesContextFactory) FactoryFinder.getFactory(FactoryFinder.FACES_CONTEXT_FACTORY); 58 LifecycleFactory lifecycleFactory = (LifecycleFactory) FactoryFinder.getFactory(FactoryFinder.LIFECYCLE_FACTORY); 59 Lifecycle lifecycle = lifecycleFactory.getLifecycle(LifecycleFactory.DEFAULT_LIFECYCLE); 60 61 69 FacesContext facesContext = contextFactory.getFacesContext(servletContext, request, response, lifecycle); 72 73 InnerFacesContext.setFacesContextAsCurrentInstance(facesContext); 75 76 try 77 { 78 chain.doFilter(request, response); 80 } 81 finally 82 { 83 try 85 { 86 facesContext.release(); 87 } 88 catch (IllegalStateException ex) 89 { 90 log.warn("Double release of faces context?", ex); 92 } 93 } 94 } 95 96 99 public void destroy() 100 { 101 } 102 103 private abstract static class InnerFacesContext extends FacesContext 107 { 108 protected static void setFacesContextAsCurrentInstance(FacesContext facesContext) 109 { 110 FacesContext.setCurrentInstance(facesContext); 111 } 112 } 113 114 117 private ServletContext servletContext = null; 118 119 122 private static final Logger log = Logger.getLogger(FacesExtensionFilter.class); 123 } 124 | Popular Tags |