In my previous post we learnt about JSF Request Lifecycle, where we studied all JSF request lifecycle phases. By using phase listeners we can get a very deep understanding of JSF request lifecycle.
JSF is a event and listeners based framework. JSF phase listeners are triggered with events fired at start and end of each request lifecycle phases. We can create our custom phase listener to fire events on start and end of each lifecycle phase.
To create a custom phase listener we needs to implements PhaseListener interface and override its methods - beforePhase, afterPhase and getPhaseId.
Here below is a custom phase listener which I created by implementing PhaseListener interface and overriding its methods.
After creating our custom phase listener we need to add it to faces-config.xml to tell JSF about it. Below code we need to put in faces-config.xml.
JSF is a event and listeners based framework. JSF phase listeners are triggered with events fired at start and end of each request lifecycle phases. We can create our custom phase listener to fire events on start and end of each lifecycle phase.
To create a custom phase listener we needs to implements PhaseListener interface and override its methods - beforePhase, afterPhase and getPhaseId.
Here below is a custom phase listener which I created by implementing PhaseListener interface and overriding its methods.
![]() |
Custom Phase Listener |
After creating our custom phase listener we need to add it to faces-config.xml to tell JSF about it. Below code we need to put in faces-config.xml.
<lifecycle>
<phase-listener>javaknowledgedirectory.listeners.MyPhaseListener</phase-listener>
</lifecycle>
Now we will run the application and check the outputs.
First we will load a page by putting link in browser, and output is -
Here above this was an initial request So After RESTORE_VIEW phase it directly redirected to RENDER_RESPONSE page.
Now we will put some data in text box and submit the button. Below is the output.
In above screen we can se that when we submitted the button, request went through all the phases and our beans method was called in INVOKE_APPLICATION phase.
I hope JSF request lifecycle is very clear. If you have any doubts please put in the comment box , I will try to resolve your queries ASAP.
_________________________________________________
***********************Keep studying***********************
No comments:
Post a Comment