This week's giveaway is in the EJB and other Java EE Technologies forum. We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line! See this thread for details.
Hi all, I would like to ask 2 questions on JSF 1.2 lifecycle:
1) All the requests for jsf resources are managed by the FacesServlet whose service method starts the lifecycle for the requested resource. So, for each request:
the web container creates a new thread to serve the request
the thread calls the service method of the FacesServlet which starts jsf lifecycle
the whole lifecylce takes place into the thread
Is this correct?
2) JSF pages are translated into servlet at a certain point of the lifecycle or not? Talking about the Render Response Phase, the JavaEE 5 tutorial says: "During this phase, the JavaServer Faces implementation delegates authority for rendering the page to the JSP container if the application is using JSP pages ..... the components will render themselves as the JSP container traverses the tags in the page."
Does it mean that the response is constructed one tag at a time while the jsp container traverses the whole view without the need to translate the page into a servlet and call the resulting jsp_service method (as for standard jsp pages)?
Actually, the web container doesn't literally create a new thread to serve the request, it obtains a thread from a Thread pool. More efficient than creating a Thread from scratch.
The thread applies the FacesServet, but only if the incoming URL matches the URL pattern(s) that were mapped in web.xml to be routed to the FacesServet. Just like any other servlet.
A single thread runs for the entire JSF request/response lifecycle, that is true.
And no, the JSF pages are not converted into servlets as far as the overall processing is concerned. They are used as templates to build the UIComponent tree that the FacesServlet uses as a reference model in order to run through its lifecycle processing. If you make any assumptions about how JSPs work in JSF based on how ordinary JSPs work, they will bite you. Even in JSF 1.2 I used Facelets, not JSP files as my View Definitions, and the JSP form of View Definition becomes completely obsolete in JSF2.
Customer surveys are for companies who didn't pay proper attention to begin with.
Joined: Jun 12, 2011
Hi Tim, thanks a lot for your help. Just a quick clarification about the second point:
"...the JSF pages are not converted into servlets as far as the overall processing is concerned..."
jsf pages are not converted into servlets at all or that
jsf pages are translated into servlets at the end of jsf lifecycle
I'm sorry but I'm still learning English.
Well, I made pasta primavera Sunday, stromboli Monday and as soon as I get through the leftovers, I've got a sack of potatoes waiting to become gnocchi, so I guess I should be extra nice to people from Italy this week.
Whether or not JSF View Definitions are converted into servlets or not is a matter of historical interest only. If they ever were, they no longer are, so no new code should be created with the assumption that the View becomes servlet code. And, since even in JSF1, application programmers were not supposed to treat View Definitions as though they were servlets, it really would be purely an academic exercise to even worry about it.
View Definitions are templates used by the Controllers to construct Views (web pages) using the Models as reference data. A View Definition should not contain executable code.
And if you spend much time reading this forum, you will notice that I tend to admonish people who code logic on the View Definitions. Not only does that break the Separation of Concerns that defines the Model/View/Controller architecture, it's a real to debug!
Joined: Jun 12, 2011
Hi Tim, thanks a lot, everything is clear now. The Force is very strong in you. If you plan to visit Italy, let me know.