Developing Web 2.0 applications
with JavaServerFaces
and Dreamweaver
>> Just Became Easier
Documentation
Search
  1. Introduction
  2. Getting Started
  3. Developing Web Sites
  4. Using Components
  5. Internationalization
  6. Code View Support
  7. Design View Support
  8. Keyboard Shortcuts
  9. Tag Object Toolbars
  10. JSF Server Behaviors
  11. Property Inspectors
  12. JSF Tag Reference
JSF Core Tag Library
  f:actionListener
  f:ajax
  f:attribute
  f:convertDateTime
  f:convertNumber
  f:converter
  f:event
  f:facet
  f:loadBundle
  f:metadata
  f:param
  f:phaseListener
  f:selectItem
  f:selectItems
  f:setPropertyActionListener
  f:subview
  f:validateBean
  f:validateDoubleRange
  f:validateLength
  f:validateLongRange
  f:validateRegex
  f:validateRequired
  f:validator
Selected f:valueChangeListener
  f:verbatim
  f:view
  f:viewParam
If you like this documentation, please take a look at my book:

12. JSF Core Tag Reference

Documentation > JSF > JSF Tag Reference > JSF Core Tag Library > f:valueChangeListener

f:valueChangeListener

The ValueChangeListener tag registers a ValueChangeListener instance on the component associated with the enclosing tag. The ValueChangeListener interface should be implemented by classes that you want to register with components that publish value change events. Any component that receives user input, such as one of the HTML select or text input components, can publish value change events. A component fires a value change event when its input changes, but only if the new input is validated successfully. You can register several ValueChangeListeners with a component and they will be invoked in the order that they are registered.

An alternative to this tag is to use a method-binding expression pointing at a value change listener method of a backing bean on the component tag itself. Notice in the example below the use of the JavaScript onchange() event to trigger form submission when the list selection changes. Without this JavaScript event, the user must manually submit the form to invoke the ValueChangeListener.

JSF Example

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" 
      xmlns:f="http://java.sun.com/jsf/core" 
      xmlns:h="http://java.sun.com/jsf/html">
<h:head />
<body>
<h:form>
	<h:selectOneMenu value="#{customerController.customer.homeAddress.country}" 
	                 converter="countryConverter" id="countryList">
		<f:selectItems value="#{countryController.countries}" var="country" 
		               itemLabel="#{country.name}" itemValue="#{country}" />
		<f:valueChangeListener type="com.mycompany.MyValueChangeListener" />
		<f:ajax />
	</h:selectOneMenu>
</h:form>
</body>
</html>
This example was formatted by JSFToolbox for Dreamweaver.

Java Code

package com.mycompany;

import javax.faces.event.AbortProcessingException;
import javax.faces.event.ValueChangeEvent;
import javax.faces.event.ValueChangeListener;

public class MyValueChangeListener implements ValueChangeListener {

	@Override
	public void processValueChange(ValueChangeEvent event)
			throws AbortProcessingException {
		System.out.println("Value changed");
	}

}

Rendered Output

Rendered f:valueChangeListener tag

Tag Attributes

binding Expression
 
The value-binding expression linking this component tag to a backing bean property.
for Text
 
If present, this attribute refers to the value of one of the exposed attached objects within the composite component inside of which this tag is nested.
type Text
Required
The type attribute expects the fully qualified Java class name of a ValueChangeListener to be created and registered on the component associated with the enclosing tag.