Chapter 7. Event Handling

   

Topics in This Chapter

  • "Life-Cycle Events" on page 274

  • "Value Change Events" on page 275

  • "Action Events" on page 281

  • "Event Listener Tags" on page 290

  • "Immediate Components" on page 292

  • "Phase Events" on page 296

  • "Putting It All Together" on page 305

Web applications often need to respond to user events, such as selecting items from a menu or clicking a button. For example, you might want to respond to the selection of a country in an address form by changing the locale and reloading the current page to better accommodate your users.

Typically, you register event handlers with components; for example, you might register a value change listener with a menu in a JSF page like this:

 

 <h:selectOneMenu valueChangeListener="#{form.countryChanged}"...>     ... </h:selectOneMenu> 

In the preceding code, the method binding #{form.countryChanged} references the countryChanged method of a bean named form. That method is invoked by the JSF implementation after the user makes a selection from the menu. Exactly when that method is invoked is one topic of discussion in this chapter.

JSF supports three kinds of events:

  • Value change events

  • Action events

  • Phase events

Value change events are fired by input components such as h:inputText, h:selectOneRadio, and h:selectManyMenu when the component's value changes and the enclosing form is submitted.

Action events are fired by command components, for example, h:commandButton and h:commandLink, when the button or link is activated. Phase events are routinely fired by the JSF life cycle. If you want to handle events, you need to have a basic understanding of that life cycle. Let's see how it works.



core JavaServer Faces
Core JavaServer Faces
ISBN: 0131463055
EAN: 2147483647
Year: 2003
Pages: 121

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net