The Java EE 6 Tutorial, Volume I

Registering a Value-Change Listener on a Component

AValueChangeListener implementation can be registered on a component that implements EditableValueHolder by nesting a valueChangeListener tag within the component’s tag on the page. The valueChangeListener tag supports two attributes:

One of these attributes must be used to reference the value-change listener. The type attribute can accept a literal or a value expression. The binding attribute can only accept a value expression, which must point to a backing bean property that accepts and returns a ValueChangeListener implementation.

The following example shows a value-change listener registered on a component:

<h:inputText  id="name" size="50" value="#{}"
     <f:valueChangeListener type="listeners.NameChanged" />

In the example, the core tag type attribute specifies the custom NameChanged listener as the ValueChangeListener implementation which is registered on the name component.

After this component tag is processed and local values have been validated, its corresponding component instance will queue the ValueChangeEvent that is associated with the specified ValueChangeListener to the component.

The binding attribute is used to bind a ValueChangeListener implementation to a backing bean property. It works in a similar way to the binding attribute supported by the standard converter tags.