Server-side Value Change Events / Listeners

Code 1 -


import javax.faces.component.UIComponent;
import javax.faces.event.ValueChangeEvent;

 * @author Tony McGuckin, IBM
public class ChangeRequestBean { 
	public ChangeRequestBean (){}
	public void valueChangeListener(ValueChangeEvent valueChangeEvent){
		// Note: valueChangeListener's are fired during the PROCESS_VALIDATIONS phase
		// but only after any binded validator(s) on the component succeeds...
		UIComponent c = valueChangeEvent.getComponent();
		System.out.println("Value changed component: " + c.getId());
		System.out.println("Old value: " + valueChangeEvent.getOldValue());
		System.out.println("New value: " + valueChangeEvent.getNewValue());
		// do something useful...
		//    perform second level check with a service...
		//    order a pizza using REST... whatever!
		if(ChangeRequestService.doesNotApproveThisNewlyValidatedValue(c.getId(), valueChangeEvent.getNewValue()){
			FacesContext context = FacesContext.getCurrentInstance();
				c.getClientId(context), new FacesMessage(
			// failover to the RENDER_RESPONSE phase...
} // end ChangeRequestBean

Code 2 - faces-config.xml

<?xml version="1.0" encoding="UTF-8"?>

Code 3 - XSP Markup

<xp:inputText id="inputText3" validator="#{validationBean.validate}"
<xp:message id="message3" for="inputText3"></xp:message>
All code submitted to OpenNTF XSnippets, whether submitted as a "Snippet" or in the body of a Comment, is provided under the Apache License Version 2.0. See Terms of Use for full details.
No comments yetLogin first to comment...