This overview, it is obvious to see the Facesservlet service method. In the process of facesservlet initialization, the global Facescontextfactory object and Lifecycle object are constructed. Can see facescontextfactory as a "request packaging factory", so it is obvious that whenever a request arrives Facesservlet, the first step is to take the request to the packaging factory inside the packaging, and the result of the packaging is a facescontext. The code is as follows:
1 Facescontext context = Facescontextfactory.getfacescontext (Servletconfig.getservletcontext (), request, response, Lifecycle);
In the packaging process, In effect, a Com.sun.faces.context.FacesContextImpl object was created, and the Facescontextimpl class inherited javax.faces.context.FacesContext from the JSF-API project. The first parameter of the Facescontextimpl's construction method is an implementation of an interface called Externalcontext, viewing its source code and seeing that the Externalcontextimpl class is coupled to the servlet API. Facescontextimpl is not related to the Servlet API. In fact, here, JSF can be used not just in a servlet environment, as in the annotations of the Externalcontext interface, using JSF in a servlet environment and using JSF in a portlet environment, is actually using a different externalcontext. The code for constructing Facescontextimpl in Facescontextfactoryimpl is as follows:
1 Facescontext ctx = new Facescontextimpl (new Externalcontextimpl (ServletContext) SC, (ServletRequest) request, ( Servletresponse) response), lifecycle);
Facescontextimpl's construction method also does another thing, which is to determine the renderkitfactory according to the configuration, obviously different renderkitfactory can produce different renderkit, and different Renderkit objects are for different clients, so for browsers, mobile devices and so on, there will be different renderkit. The code in the Facescontextimpl construction method is as follows:
1 this.externalContext = ec;
2 setCurrentInstance(this);
3 this.rkFactory = (RenderKitFactory)FactoryFinder.getFactory(FactoryFinder.RENDER_KIT_FACTORY);
In code we often use the facescontext.getcurrentinstance () static method to get the Facescontext object corresponding to the current request. In fact, there is a static Threadlocal object in the Facescontext class that holds the Facescontext object corresponding to the current request thread, and setcurrentinstance in the above code (this) is to put the current structure out of the Facescontext object into the threadlocal inside.
Facescontext created, as mentioned above, to let him through the lifecycle "Filter Chain" step-by-step processing. So, filter chain inside put is a filter, then lifecycle this chain inside put is what? The answer is phases.
Facesservlet let Facecontext through the lifecycle processing, divided into two parts. One part is to invoke the lifecycle Execute method, execute the logic, and the second part is to invoke the lifecycle Render method to render the response. The code in Facesservlet.service is as follows:
1 lifecycle.execute(context);
2 lifecycle.render(context);