Understanding the JSF Event Model
The JSF event model is based on the event model defined by the JavaBeans specification. In this model, an event is represented by an instance of an event class. An event source object fires an event by calling an event notification method on event listener objects registered to receive the event, passing a reference to the event object as a notification method argument.
Let’s look at what this means in more detail. All
JSF event classes extend the
javax.faces.event.FacesEvent class:
package javax.faces.event;
import java.util.EventObject;
import javax.faces.component.UIComponent;
...
public abstract class FacesEvent extends EventObject {
public FacesEvent(UIComponent component) {
super(component);
}
public UIComponent getComponent( ) {
return ((UIComponent) getSource( ));
}
...
}The FacesEvent class extends
the standard Java event superclass
java.util.EventObject and has a constructor that
takes the UIComponent event source object as an
argument. It also implements a type-safe accessor method for the
event source object.
When a user clicks a button, it triggers an event represented by the
javax.faces.event.ActionEvent class:
package javax.faces.event;
import javax.faces.component.UIComponent;
public class ActionEvent extends FacesEvent {
public ActionEvent(UIComponent component) {
super(component);
}
...
}Other events are represented by similar concrete subclasses, such as
the javax.faces.event.ValueChangeEvent, which
signals a value change.
Along ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access