• No replies
289 Posts

Pinned topic removePhaseListener not working

‏2012-04-02T03:04:55Z |
I can add a PhaseListener with lifecycle.addPhaseListener(cpl) and it picks it up right away.

This is a special purpose PhaseListener I want to add only in a certain set of conditions, and I want to remove it after the request where those conditions are met.

lifecycle.removePhaseListener(cpl) doesn't remove it and all subsequent events show that it is running and I also tried.

context.getViewRoot().removePhaseListener(cpl) and still all subsequent events show that it is still running.

All that listener does right now is

public void beforePhase(PhaseEvent event) {
// Hello World
LOGGER.trace(">>>>>>>>>>>>>>>>>>>>>>>>> beforePhase() <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<");
LOGGER.trace(">>>>>>>>>>>>>>>>>>> PhaseId =" + event.getPhaseId() + " <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<");
LOGGER.trace(">>>>>>>>>>>>>>>>>>>>>>>>> Hello World <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<");


public PhaseId getPhaseId() {
// This will fire this phase listener on all phases

return PhaseId.ANY_PHASE;

because I wanted to get the mechanism working before spending any time on the internals.

So what is the proper way to dynamically add a PhaseListener to a lifecycle and remove it when done?