Introduction
In this article, we will be learning about the facelets in JSF. The overall application development framework is Java Server Faces. It has a lot of features, one of them is the view handler. Facelets is a JSF view handler. JSP was the default view handler before JSF 2.0. The problem was that JSP didn't integrate well with JSF's component-based framework. Facelets were built from the ground up with JSF in mind.
To use the JSF tag we need to use the following namespace.
<html
xmlns="https://www.w3.org/1999/xhtml"
xmlns:ui="https://java.sun.com/jsf/facelets"
>
Lifecycle of a Facelets
A JavaServer Faces application's lifetime is defined by the JavaServer Faces specification. The instructions below demonstrate how to create a Facelets-based application.
Step1: The lifecycle begins when a client submits a new request for a Facelets-created web page. JSF builds a new javax.faces.component tree. Placed in the FacesContex as UIViewRoot.
Step2: The view is ready to be filled with rendering components. If accessible, the UIViewRoot is applied to the Facelets.
Step3: In response to the client, the newly constructed view is rendered.
Step4: The status of this view is saved for the next request when it is rendered. It's possible to save the status of input components and form data.
Step5: The client can interact with the view and ask the JavaServer Faces application for another view. The saved view is restored from the preserved state at this point.
Step6: The restored view is passed through the JavaServer Faces lifecycle, which will either build a new view or re-render the current view if no validation errors were found and no action was taken.
Step7: The saved view is rendered again if the same view is requested.
Step8: If a new view is requested, proceed to Step 2.
Step9: The new view is rendered in response to the client.