background image

The ValueChangeListener

<< Value-Change Event Handler | Creating Custom UI Components >>
<< Value-Change Event Handler | Creating Custom UI Components >>

The ValueChangeListener

This ValueChangeListener instance handles the event of entering a value in the field
corresponding to the component. When the user enters a value, a value-change event is
generated, and the processValueChange(ValueChangeEvent) method of the
ValueChangeListener
class is invoked.
Instead of implementing ValueChangeListener, you can write a backing bean method to
handle this event. To do this, you move the processValueChange(ValueChangeEvent) method
from the ValueChangeListener class, called NameChanged, to your backing bean.
Here is the backing bean method that processes the event of entering a value in the name field on
the bookcashier.jsp page:
public void processValueChange(ValueChangeEvent event)
throws AbortProcessingException {
if (null != event.getNewValue()) {
FacesContext.getCurrentInstance().
getExternalContext().getSessionMap().
put(
"name", event.getNewValue());
}
}
The page author can make this method handle the ValueChangeEvent object emitted by a
UIInput
component by referencing this method from the component tag's
valueChangeListener
attribute. See
"Referencing a Method That Handles a Value-change
Event" on page 372
for more information.
Writing Backing Bean Methods
The Java EE 5 Tutorial · September 2007
408