Basically, I need to call a method after RENDER_RESPONSE phase. I tried this:
<f:phaseListener type="com.examples.MyPhaseListener"/>
The above listener is listenening all the time even for ajax calls. I tried
rendered="#{!facesContext.postback}"
but its not applicable here I guess. So I tried this as mentioned in this post Is it possible to disable f:event type="preRenderView" listener on postback?:
public void beforePhase(PhaseEvent pe) {
if (!FacesContext.getCurrentInstance().isPostback()) {
//do nothing
}
}
public void afterPhase(PhaseEvent pe) {
if (!FacesContext.getCurrentInstance().isPostback()) {
if (pe.getPhaseId() == PhaseId.RENDER_RESPONSE) {
//call a method
}
}
}
It is working but is there any other way to disable the listener after the initial response? I also tried preRenderComponent but it is called in before RENDER_RESPONSE phase and it looks like it is not rendering response until the method is out of the stack ( basically it is not asynchronous). So I feel there is not much advantage of SystemEvents like preRenderView and preRenderComponent when compared to calling them in PostConstruct.