10.12.2012 Views

The Java EE 5 Tutorial (PDF) - Oracle Software Downloads

The Java EE 5 Tutorial (PDF) - Oracle Software Downloads

The Java EE 5 Tutorial (PDF) - Oracle Software Downloads

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

User Interface Component Model<br />

304<br />

user activates a component, such as by clicking a button, an event is fired. This causes the<br />

<strong>Java</strong>Server Faces implementation to invoke the listener method that processes the event.<br />

<strong>Java</strong>Server Faces technology supports three kinds of events: value-change events, action events,<br />

and data-model events.<br />

An action event occurs when the user activates a component that implements ActionSource.<br />

<strong>The</strong>se components include buttons and hyperlinks.<br />

A value-change event occurs when the user changes the value of a component represented by<br />

UIInput or one of its subclasses. An example is selecting a check box, an action that results in<br />

the component’s value changing to true. <strong>The</strong> component types that can generate these types of<br />

events are the UIInput, UISelectOne, UISelectMany, and UISelectBoolean components.<br />

Value-change events are fired only if no validation errors were detected.<br />

Depending on the value of the immediate property (see “<strong>The</strong> immediate Attribute” on page 326)<br />

of the component emitting the event, action events can be processed during the invoke<br />

application phase or the apply request values phase, and value-change events can be processed<br />

during the process validations phase or the apply request values phase.<br />

A data-model event occurs when a new row of a UIData component is selected. <strong>The</strong> discussion<br />

of data-model events is an advanced topic. It is not covered in this tutorial but may be discussed<br />

in future versions of this tutorial.<br />

<strong>The</strong>re are two ways to cause your application to react to action events or value-change events<br />

emitted by a standard component:<br />

■ Implement an event listener class to handle the event and register the listener on the<br />

component by nesting either a valueChangeListener tag or an actionListener tag inside<br />

the component tag.<br />

■ Implement a method of a backing bean to handle the event and refer to the method with a<br />

method expression from the appropriate attribute of the component’s tag.<br />

See “Implementing an Event Listener” on page 393 for information on how to implement an<br />

event listener. See “Registering Listeners on Components” on page 357 for information on how<br />

to register the listener on a component.<br />

See “Writing a Method to Handle an Action Event” on page 404 and “Writing a Method to<br />

Handle a Value-Change Event” on page 405 for information on how to implement backing bean<br />

methods that handle these events.<br />

See “Referencing a Backing Bean Method” on page 368 for information on how to refer to the<br />

backing bean method from the component tag.<br />

When emitting events from custom components, you must implement the appropriate Event<br />

class and manually queue the event on the component in addition to implementing an event<br />

listener class or a backing bean method that handles the event. “Handling Events for Custom<br />

Components” on page 427 explains how to do this.<br />

<strong>The</strong> <strong>Java</strong> <strong>EE</strong> 5<strong>Tutorial</strong> • June 2010

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!