Introduction to JSF Life Cycle
JavaServer Faces web applications are built using reusable, self-contained components as building blocks, making building web apps faster and easier.
The most interesting aspect of JavaServer Faces, which sets it apart from action-based web application frameworks, Such as Spring Web MVC (Model-View-Controller), Struts or plain Servlets in JavaServer pages is that it’s Component-based. This means that in JSF the building blocks of your application are reusable and self-contained components.
A Component can be any part of a web application. It can be as simple as a standard HTML form-control, such as a text input field or a button or as complex a table with sorting and pagination support.
A calendar or a chart or any other part of a web application that you can think of the framework manages the components on a page and takes care of a lot of things such as taking user input from form fields, validating and converting data and storing it into model objects and invoking actions.
JSF comes with a number of standard components and there are also libraries available with many ready to use components.
4.5 (2,185 ratings)
3. Web UI framework
JavaServer Faces is focused on the user interface part of web applications – you define pages in the Facelets view definition language.
The standard view definition language used in JSF is called Facelets.
Different Regular Phases of JSF Lifecycle
There are six different regular phases inside the JSF Life Cycle. The above diagram shows the typical order where the six phases perform.
1. Restore View Phase
This phase begins each time a consumer requests a JSF page by simply clicking on a link, button and so on. In this page view generation, the binding of components to the event handlers and validators is performed as well as the view is preserved within the FacesContext object.
2. Apply request value
The objective of this phase is made for each component to retrieve the current state
3. Process Validations Phase
In this phase, local values stored to get the component in the tree will be in comparison to the validation rules authorized to get the components.
4. Update Model Values Phase
Following verifying that data is valid in the last phase local values of elements could be started related to server-based object properties, for example, backing beans.
5. Invoke Application Phase
Ahead of this phase the component values had been transformed, validated, as well as, put on the bean objects so that you can utilize these to perform the application’s business logic.
6. Render Response Phase
This phase fetches a new view if needed using values from server-side beans then we output the view using the values that are in the tree and then for beans that are not on the request in other words on the session scope or application scope we will then save those the current state.
Understanding Faces Flows with demo application in real life example
Below is the demo application of face flows with an example:
The Checkout Process
- Enter shipping details
- Name and Address
- Enter payment details
- Name, credit card type and number
- Review order
- Confirm or Cancel the order
- Payment succeeded or failed
Let see Checkout Flow with Flow Nodes in the below diagram.
A flow is consisting of a number of nodes. Each node is stepped in the flow that performs some function and it specifies which node should be called next. In the definition of a flow, you define the nodes and the rules for navigating between them. In this diagram, you see the nodes of the checkout flow.
It starts with shipping, then payment and review then the execute node which is where the payment is made and the order is fulfilled and finally check result success or failure, and then the process is finished.
Kinds of Flow Nodes in JSF Life Cycle
There are five different kinds of nodes in JSF Life Cycle.
- Display a view (page)
Method call node
- Call a method
- Select one of a series of cases
- End the flow
Flow call node
- Call another flow
Flows are Similar to Methods
Below are similar flow methods in the JSF life cycle:
Entry point, Parameters, Exit points
- May return one or more values
- Flow-scoped beans are like local variables
Nested Flow Calls
- Call stack
A call stack is used to keep track of invocations and scopes of flows, exactly like how it works with the method When a flow is called a new entry is pushed into the stack and when flow returns its entry is popped from the stack. There are two ways to specify the configuration of flow.
XML Configuration File
- In faces-config.xml or in a separate file
In Java using the Flow Builder API
- CDI producer method with @FlowDefinition annotation
Conclusion: JSF Life Cycle
Java Server Faces (JSF) is the standard concept for establishing web applications in Java. Even so, throughout the development as well as, deployment of JSF applications, there are numerous performance and configurations that need to be applied to help make the applications safer, reliable, as well as, effective.
This has been a guide on JSF Life Cycle. Here we have discuss the Six Different Regular Phases of JSF lifecycle and five different kinds of nodes in the JSF Life Cycle. You may also look at the following articles to learn more –