JSF Showcase
f:phaseListener
f:phaseListener enables the possibility of adding a PhaseListener as part of the UIViewRoot. Notice that this method differs from thefaces-config.xml
method as the latter applies from the beginning, and this only applies when the tag is being rendered.
General Usage
Usetype
for setting the class name that implements PhaseListener, or use binding
to use an EL expression that evaluates to a PhaseListener. In the example below, you can see that more phases apply from PhaseListener when doing the postback, as at that moment the tag was applied and PhaseListener ready.
Source Code
<ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:f="http://xmlns.jcp.org/jsf/core" xmlns:h="http://xmlns.jcp.org/jsf/html" xmlns:ui="http://xmlns.jcp.org/jsf/facelets"> <h:form> <f:phaseListener type="com.liferay.faces.showcase.bean.PhaseListenerBean"/> <h:commandLink value="#{i18n['submit']}"> <f:ajax render="@form"/> </h:commandLink> <h:outputText id="phaseText" value="#{inputTextModelBean.text}" escape="false"/> </h:form> </ui:composition>
public class PhaseListenerBean implements PhaseListener { @Override public void afterPhase(PhaseEvent event) { InputTextModelBean inputTextModelBean = getInputTextModelBean(event.getFacesContext()); inputTextModelBean.setText(inputTextModelBean.getText() + "<br/>PhaseListenerBean in afterPhase of " + event.getPhaseId()); } @Override public void beforePhase(PhaseEvent event) { InputTextModelBean inputTextModelBean = getInputTextModelBean(event.getFacesContext()); inputTextModelBean.setText(inputTextModelBean.getText() + "<br/>PhaseListenerBean in beforePhase of " + event.getPhaseId()); } public InputTextModelBean getInputTextModelBean(FacesContext facesContext) { ELResolver elResolver = facesContext.getApplication().getELResolver(); ELContext elContext = facesContext.getELContext(); InputTextModelBean inputTextModelBean = (InputTextModelBean) elResolver.getValue(elContext, null, "inputTextModelBean"); if (inputTextModelBean.getText() == null) { inputTextModelBean.setText(""); } return inputTextModelBean; } @Override public PhaseId getPhaseId() { return PhaseId.ANY_PHASE; } }
Liferay Faces Bridge Implementation 5.0.0 + Showcase Common 3.1.1 + Liferay Faces Util 3.4.1 + Mojarra 2.2.20