Portal Showcase

f:valueChangeListener

Its easy to implement a custom ValueChangeListener and use it in any EditableValueHolder Facelet component.

General Usage

Set type attribute with a fully qualified Java class name implementing ValueChangeListener to be applied when the parent EditableValueHolder value changes. Important note: there is usually confusion about ValueChangeListener and client-side events. ValueChangeListener are only server-side related events. For using client-side ones, just use any of the provided mechanism (f:ajax with event attribute, etc).

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>
		<h:messages layout="table" />
		<h:inputText value="#{validationModelBean.otherText}" label="#{i18n['f-validator-label']}">
			<f:valueChangeListener type="com.liferay.faces.showcase.bean.ShowcaseValueChangeListener"/>
		</h:inputText>
		<h:commandButton value="#{i18n['submit']}">
			<f:ajax	execute="@form" render="@form"/>
		</h:commandButton>
	</h:form>

</ui:composition>
public class ShowcaseValueChangeListener implements ValueChangeListener {

	@Override
	public void processValueChange(ValueChangeEvent event) throws AbortProcessingException {

		FacesContext facesContext = FacesContext.getCurrentInstance();

		FacesMessage facesMessage = new FacesMessage("The valueChangeListener was called." + "The new value is " +
				event.getNewValue());
		facesContext.addMessage(null, facesMessage);
	}

}
Liferay Faces Bridge Implementation 4.0.0 + Liferay Faces Portal 3.0.0 + Showcase Common 3.0.0 + Liferay Faces Util 3.0.0 + Mojarra 2.2.13