users@javaserverfaces.java.net

Re: How the faces servlet gets a JSF-view

From: Ryan Lubke <Ryan.Lubke_at_Sun.COM>
Date: Thu, 06 Mar 2008 09:16:43 -0800

Hi Martin,

Please see inline....

Martin Höller wrote:
> Hi!
>
> I'm relatively new to JSF and I'm trying to find out how the JSF servlet
> works behind the scenes (due to another problem I have). Please correct me
> if I'm wrong.
>
> The first phase in JSF is the "Restore View" phase which needs to build a
> component tree if a page is displayed for the first time. To build this
> tree the input page needs to be obtained and read.
>
Correct, Restore View is the first phase, but there are two aspects to
this phase:
  1. GET request to the view
  2. POST request to the view (i.e. form submission).

In the GET case, we don't build the component tree. We instead create
a new view root, and skip immediately to the Render Response phase.
Due to issues with JSP, this is when the view will be built.

> For example if I have a URL like
> http://localhost:8080/mywebapp/faces/mypage.jsp a page "mypage.jsp" has to
> be read from somewhere. (I assume prefix mapping for the servlet and
> default values for all other configuration parameters for now.)
>
> How does the faces servlet read this input stream? Is it simply a file i/o?
> I assume it's not, as (at least with JSF 1.1) it also works with OpenCms
> that stores JSP pages in a database.
>
The FacesServlet really doesn't do much outside of invoking the Lifecycle.
The ViewHandler does this heavy lifting. That said, we use the Servlet
RequestDispatcher to invoke the JSP.

Here are the steps for that in order (assuming JSF 1.2 here)
 - ViewHandler.renderView() is called
 - request is dispatched to the target JSP
 - the processing of the JSP causes the view to
   be constructed and all template text inserted
   as transient UIOutput instances into their proper
   locations.
- request dispatch returns
- UIViewRoot.encodeAll is called to cause the
  tree to be rendered
- any content found after the closing f:view is
  written