Previous Section  < Day Day Up >  Next Section

Chapter 8. Handling Events

When the user clicks a button or link, changes a value in a field, or makes a selection in a list, the application may need to react. JSF user interface components signal user actions by firing an event handled by application code that has registered itself to be notified of the event. It's a model borrowed from traditional GUI frameworks, making it easy to develop and maintain the code for each specific user action in a separate code module. You can even use multiple event handling modules for different aspects of the processing, such as one that logs the action and another that acts on it.

On the surface, the JSF model looks the same as the event model used for standalone applications, but there's a twist: with JSF, the user actions take place in a client (e.g., a browser) that has no permanent connection to the server, so the delivery of some types of event is delayed until a new connection is established (e.g., when the user submits a form). To deal with this difference, JSF defines a strict request processing lifecycle, where events are generated and handled in different phases.

In this chapter, we first look at the event model and how it relates to the request processing lifecycle to understand what's going on. We then implement event handling for parts of the sample application.

    Previous Section  < Day Day Up >  Next Section