As the name suggests, a phase listener is capable to listen to the start and end of each of the six JSF life-cycle phases (a detailed diagram of how JSF phases interact with each other is available in Appendix, The JSF Life Cycle):
Restore the View phase
Apply the Request Values phase
Process the Validations phase
Update the Model Values phase
Invoke the Application phase
Render the Response phase
You can easily capture the events of each phase by following these three steps:
Implementing the
PhaseListener
interface.Overriding the
afterPhase
,beforePhase
, andgetPhaseId
methods.Configuring the phase listener in
faces-config.xml
.
A good point to start is a simple but useful PhaseListener
that can be used to debug the phases. If you ever had the curiosity to see what is happening in JSF request lifecycle, then you can use this phase listener, which is defined as follows:
public class DebugPhaseListener implements PhaseListener { public DebugPhaseListener() { } ...