users@javaserverfaces.java.net

Re: How the faces servlet gets a JSF-view

From: Ryan Lubke <Ryan.Lubke_at_Sun.COM>
Date: Fri, 07 Mar 2008 08:18:31 -0800

Martin Höller wrote:
> Hi Ryan!
>
> Thanks for your quick response.
>
> On Thursday 06 March 2008 Ryan Lubke wrote:
>
>> Martin Höller wrote:
>>
>>> 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).
>>
>
> Ok, so far only the GET request is what is of interest for me.
>
>
>> 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.
>>
>
> Ok, let me summarize: the FacesServlet basically does this
>
> lifecycle.execute(context);
> lifecycle.render(context);
>
> In case of a GET request the lifecycle.execute() call doesn't execute any
> phase and the lifecycle.render() is the next relevant method. This method
> executes the RenderResponsePhase which in turn calls the ViewHandlerImpl's
> renderView() method. In the ViewHandler the request is dispatched to the
> JSP servlet. Correct?
>
Yep.
>
>> The FacesServlet really doesn't do much outside of invoking the
>> Lifecycle.
>>
>
> But doesn't the UIViewRoot has to be built somehow? And doesn't this imply
> the reading of the actual JSP page? I don't get this.
>
I posted the details on how this works in my original reply. Here they
are again:

- 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

> My final problem is, that I want to use JSF with OpenCms which stores all
> pages in a database. Usually files are accessed via the opencms servlet
> (http://localhost:8080/mywebapp/opencms/somefile.jsp). Integration with JSF
> 1.1 is possible by setting up the FacesServlet as usual and accessing the
> pages via http://localhost:8080/mywebapp/faces/opencms/somefile.jsp. With
> JSF 1.2 this returns an empty or heavily truncated page (don't know yet on
> what this depends) an no errors or exceptions can be found in the log
> files.
>
My theory is that when going through the opencms servlet they may be
wrapping
the request/response with custom wrappers to handle their JSP access.
In earlier
versions of 1.2, we'd silently fail if the wrapper, at the time we were
processing,
wasn't what we expected. I'd recommend using JSF 1.2_08 and trying your
application
again. We've added error messages that would confirm if this was the
case or not.
> Thanks for any further help,
> - martin
>