concept JSF life cycle in category seam

appears as: JSF life cycle, JSF life cycle, The JSF life cycle, JSF life cycles
Seam in Action

This is an excerpt from Manning's book Seam in Action.

Start by focusing your attention on the form that is used to submit a new tip at the bottom of the page. Each input element is bound to properties on the GolfTip entity class using EL notation (e.g., #{tip.author}). When used in the value attribute of an input element, the EL notation acts as a value-binding expression. It captures the form value and transfers it to an instance of the GolfTip entity class as part of the JSF life cycle. Here’s the (slightly trimmed-down) fragment of the JSF template that renders the form:

For us to use Seam in an application server environment, it must be hooked into the life cycle of the servlet container. When the application starts, the servlet container bootstraps Seam, at which time Seam loads its contextual container, scans for components, and begins serving out component instances. Once running, the servlet container also notifies Seam when HTTP sessions are opened and closed. Seam also enrolls itself in servlet requests by registering a servlet filter, a servlet, and a JSF phase listener. It is through these servlet and JSF phase events that Seam manages its container and enhances the default JSF life cycle.

Before getting knee-deep into configurations, I want to provide context to the phrase life cycle, as it’s being thrown around quite casually. I’ve referred to a servlet context life cycle, a request life cycle, a JSF life cycle, and a Seam life cycle. Let’s sort them out.

The servlet context life cycle represents the entire lifespan of the web application. It is used to bootstrap services, such as the Seam container. The request life cycle, on the other hand, is the overarching life cycle for a single request. It envelops the JSF and Seam life cycles. It lasts from the time the browser requests a URL handled by the application to the time the server finishes sending the request to the browser. The JSF life cycle is fairly limited in scope. It’s confined to the service() method of the JSF servlet and doesn’t concern itself with non-JSF requests. The Seam life cycle is broader. On the one hand, it works alongside the JSF life cycle, weaving in extra services at strategic extension points. On the other hand, it extends beyond the JSF life cycle, both vertically, capturing events that occur outside the scope of the JSF servlet, and horizontally, by participating in non-JSF requests. You can think of the Seam life cycle as an evolution of the JSF life cycle.

That wraps up the configuration necessary to allow Seam to partake in requests. From here on, I’ll refer to the combination of the Seam servlet filter and the JSF life cycle, which Seam now has a hand in, as the Seam life cycle. Figure 3.2 illustrates the two paths that a request can take as it enters the Seam life cycle. The SeamFilter can also wrap additional servlets such as Struts, Spring MVC, or DWR, allowing you to tap into the Seam container from these third-party frameworks as needed.

Figure 3.2. Requests are preprocessed by the Seam filter, proceeding to the JSF servlet or the Seam resource servlet.

With the configuration of Seam out of the way, let’s take a step back and consider what the JSF life cycle is like without Seam. The goal of this exercise is to gain an appreciation for the assumptions made by the JSF specification and where those assumptions come up short. Contrasting the native JSF life cycle with the version enhanced by Seam helps you understand why Seam is relevant and clarifies when you should choose the Seam facilities over the JSF equivalents that they replace. I’ll start by reviewing the general principles of JSF and then walk you through the JSF life cycle.

Some people consider the JSF life cycle to be overly complex. This issue I will actually defend in JSF’s favor. I don’t believe the problem is being accurately represented. The JSF life cycle is a good decomposition of the logical phases that occur in just about any web request, written in any programming language, and run on any platform. The problem is that the life cycle is missing some areas of coverage. The lack of an action-based front controller, like Struts, is a perfect example. As a result of these oversights, developers have been forced to use the framework in ways for which it wasn’t intended or to bolt on haphazard solutions that seek to fill these voids.[8] Having to constantly compensate for these problems is where the pretense of complexity manifests itself.