tags:

views:

38

answers:

2

Hi in JSF i need to perform some action when each request of the user ends. I need some kind of interceptor but i don't know how to do it. I need help with this please. Thanks

+1  A: 

Hey

I recommend BalusC's blog: http://balusc.blogspot.com/2006/09/debug-jsf-lifecycle.html

This article shows you how to intercept the JSF lifecycle and debug the information. This will also make it available for you to find out where your request ends.

If you posted some code here it could also help us find out where the true problem lies. Here is an excerpt of the code that you need to implement to debug the lifecycle:

package mypackage;

import javax.faces.event.PhaseEvent;
import javax.faces.event.PhaseId;
import javax.faces.event.PhaseListener;

public class LifeCycleListener implements PhaseListener {

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

    public void beforePhase(PhaseEvent event) {
        System.out.println("START PHASE " + event.getPhaseId());
    }

    public void afterPhase(PhaseEvent event) {
        System.out.println("END PHASE " + event.getPhaseId());
    }

}
ChrisAD
+1  A: 

If you want to have the FacesContext available, then the best place is the afterPhase of PhaseID.RENDER_RESPONSE inside a PhaseListener. For example:

public class MyPhaseListener implements PhaseListener {

    public PhaseId getPhaseId() {
        return PhaseId.RENDER_RESPONSE;
    }

    public void beforePhase(PhaseEvent event) {
        // No operation here.
    }

    public void afterPhase(PhaseEvent event) {
        FacesContext context = event.getFacesContext();
        // Do your thing here with the FacesContext.
    }

}

If you don't need the FacesContext, then the best place is after the line chain.doFilter(request, response) inside a Filter. For example:

public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) {
    chain.doFilter(request, response);
    // Do your thing here.
}
BalusC
Hehe funny how I just refered to an article on your site before you answered this post aswell =)
ChrisAD