Search code examples
jsfphaselistener

Understanding the PhaseListener.getPhaseId


HI,

I need clarification on implementing the PhaseListener class. The following is the two different overriding implementation for the PhaseListener.getPhaseId

@Override
public PhaseId getPhaseId() {       
    return PhaseId.ANY_PHASE;
}

and

@Override
public PhaseId getPhaseId() {       
    return PhaseId.RESTORE_VIEW;
}

What could be the significant difference in those two implementations?. What will be the impact?


Solution

  • As stated in the PhaseListener#getPhaseId() javadoc, this indicates for which PhaseId the current PhaseListener implementation should execute the implemented beforePhase() and afterPhase() methods. In the first example, they will be executed on any phase and in the second example, they will be executed in the RESTORE_VIEW phase only (which is the firstmost phase of the JSF lifecycle).