Pages

Monday, May 07, 2012

JSF 2 Tip of the Day: Learning the JSF Lifecycle with a PhaseListener

I have to do some JSF training in the next couple of weeks for some of the staff at the company where I work. The learning curve for JSF has often been called a vertical wall. In part this is due to the JSF Lifecycle. The JSF Lifecycle has a number of phases, and before and after each phase there is an extension point where we can intervene in the process using a PhaseListener.

Since the PhaseListener intercepts the process, you can use it to learn the phases. The PhaseListener below is an example of one that reports on all PhaseEvents. You should modify it to learn what occurs during each phase.

PhaseListenerImpl.java

Here is the output:
INFO: Before Phase: RESTORE_VIEW 1 invoked.
INFO: After Phase: RESTORE_VIEW 1 invoked.
INFO: Before Phase: APPLY_REQUEST_VALUES 2 invoked.
INFO: After Phase: APPLY_REQUEST_VALUES 2 invoked.
INFO: Before Phase: PROCESS_VALIDATIONS 3 invoked.
INFO: After Phase: PROCESS_VALIDATIONS 3 invoked.
INFO: Before Phase: UPDATE_MODEL_VALUES 4 invoked.
INFO: After Phase: UPDATE_MODEL_VALUES 4 invoked.
INFO: Before Phase: INVOKE_APPLICATION 5 invoked.
INFO: After Phase: INVOKE_APPLICATION 5 invoked.
INFO: Before Phase: RENDER_RESPONSE 6 invoked.
INFO: After Phase: RENDER_RESPONSE 6 invoked.

0 comments :