JSF Event Model

Jsf is provided with many event handler. Before we go into event handling, let's understand what is event and listener?

Event: Event can be as simple as changing the value of a field or click on a button.

Listener: For every event we need to specify a listener which will get called when a specific event occurs.

Application Events: These are the event which occur in a application on the basis of user interaction with the application. e.g user press cancel button.

Application Event Listener in JSF:

->valueChangeListener: When user interact with any input UI component this particuler event will get fired and specified listener will get executed.

It can be implemented with two ways:

1) For the input component we have to specify a specific bean's method in valueChangeListener attribute.

2) We need to implement ValueChangeListener and specify the same for a specific input component.

->actionListener: When user click on a buttong or link component, this particuler event will get fired and listener will get executed.

It can be implemented with two ways:

1) For the button\link component we have to specify a specific bean's method in actionListener attribute.

2) We need to implement ActionListener and specify the same for a specific input component.

LifeCycle\Phases Events: These are the event which incudes life cycle phases and system events. We can implement the same by implementing PhaseListener interface and register the same in faces-config.xml

System Application Events:

->PostConstructApplicationEvent: It will get fired after application is started.

->PreDestroyApplicationEvent: It will get fired before application is destroyed.

These can be implemented as:

1) Using SystemEventListener: We need to implement a SystemEventListener and register the same in faces-config.xml