This example demonstrates the use of a
PhaseListener
which is set in the web.xml file. It also includes a component tree renderer which is also a PhaseListener
. Facelets includes a component renderer for debugging purposes. You must include the <ui:debug/>
tag in your xhtml file to use it.Note: The component renderer for debugging components has a Javascript error which was introduced in Facelets 1.1.12 through 1.1.14 which will not render the Component tree. You must use either Facelets 1.1.11 or 1.1.15.B1 to have the component tree render.
Here is the sample code on Bitbucket: JSFPhaseListeners
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.bluelotussoftware.jsf.phaselisteners; | |
import java.util.logging.Logger; | |
import javax.faces.event.PhaseEvent; | |
import javax.faces.event.PhaseId; | |
import javax.faces.event.PhaseListener; | |
/** | |
* | |
* @author John Yeary <jyeary@bluelotussoftware.com> | |
* @version 1.1 | |
*/ | |
public class PhasePrinterListener implements PhaseListener { | |
private static final Logger logger = Logger.getLogger("global"); | |
private static final long serialVersionUID = 3131268230269004403L; | |
/** | |
* Creates a new instance of PhasePrinterListener | |
*/ | |
public PhasePrinterListener() { | |
} | |
@Override | |
public void afterPhase(PhaseEvent event) { | |
logger.info("After - " + event.getPhaseId().toString()); | |
if (event.getPhaseId() == PhaseId.RENDER_RESPONSE) { | |
logger.info("Done with request!\n"); | |
} | |
} | |
@Override | |
public void beforePhase(PhaseEvent event) { | |
if (event.getPhaseId() == PhaseId.RESTORE_VIEW) { | |
logger.info("Processing new request!"); | |
} | |
logger.info("Before - " + event.getPhaseId().toString()); | |
} | |
@Override | |
public PhaseId getPhaseId() { | |
return PhaseId.ANY_PHASE; | |
} | |
} |