Question

I have this PhaseListner:

public class CheckAccessInterceptor implements PhaseListener {
    private static final long serialVersionUID = -311454347719850720L;
    private static Logger logger = Logger.getLogger(CheckAccessInterceptor.class);

    @Override
    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());
    }

}

Is it possible to get ManagedBean's name and invoked method's name from PhaseEvent object? How?

UPDATED:

I find solution here but looks like it doesnt work with Ajax. So I dont know what to do.

Was it helpful?

Solution 2

So right answer is here

But I must warn you, it work with actions only, not actionlisters.

maple_shaft's solution works too, but in my opinion BalusC's solution better.

OTHER TIPS

Anything is possible, and I am sure there is a far easier way to do this, but I gave up and went straight to the source.

The UIViewRoot has a private field events that during the INVOKE APPLICATION phase will have a list of lists that have all of the events to broadcast at each respective Phase. The only way I could think of doing this is to use reflection to obtain that list.

Field field = UIViewRoot.class.getDeclaredField("events");
field.setAccessible(true);
ArrayList<ArrayList<SystemEvent>> events =
  (ArrayList<ArrayList<SystemEvent>>)field.get(
     FacesContext.getCurrentInstance().getViewRoot());

for (ArrayList<SystemEvent> phaseEvents : events) {
   for (SystemEvent event : phaseEvents) {
      // is this the event you are looking for?
   }
}

I think somewhere I hear Gosling and the original authors of the JSF spec crying right now.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top