Sie sind auf Seite 1von 16

15

Section 15 ADF Faces Component Events and Validation

Using Event Listeners


Event Object
Ive been clicked! Does anyone care?

Yes Im listening! Now Ill get to work

Event Listener

Event Source

Responding to Action Events


Command components raise action events. Code to respond to the action event can be in the backing bean or external class. Stub code is generated by JDeveloper on demand. The action is registered in the page source. Action events are called in the Invoke Application phase of the life cycle. Action methods are the last to execute after other listeners, such as valueChange events.

Creating Action Methods


To create an action method:
Invoke the action binding editor Choose existing bean and method, or create new

JDeveloper:
If the bean does not exist, creates Java class and registers as a managed bean If the method does not exist, creates a method stub in the managed bean class Adds the method to the action property of component

Add your own code. Action methods return a String outcome.

Using Action Listeners


Action listeners differ from action methods:
Action listeners: Contain code to respond to an action Do not return a value Execute after value change listeners
Action methods: Are used for navigation Return a String outcome Execute last

Both can be initiated by the same action, such as a button click.

Value Change Events


Input components raise value change events. Code for the value change listener can be in the backing bean or external class. Stub code is generated by JDeveloper. The value change event is registered in the page source. Value change events are processed in the Invoke Application phase of the life cycle. Value change events fire before action events.

Listening for Value Change Events


Select the input component in the visual editor. Edit the valueChangeListener property and select a bean and method, or create a new one. JDeveloper:
Creates the method in the managed bean if it doesnt already exist Adds the method to the valueChangeListener property in the page source

Add your code.

Event and Listener Execution Order


The order in which the events and listeners fire is:
1. Validator (managed bean method that performs validation on the components value) 2. Value change listener (managed bean method to handle value-change events) 3. Action listener (managed bean method to handle action events) 4. Action method (managed bean method to return a logical outcome String that is used in navigation)

ADF Faces Enhanced Event Handling


ADF Faces adds to JSF event handling by providing:
Partial page rendering (PPR) JavaScript

Other ADF Faces Events


Property Inspector of ADF Faces components displays appropriate event listeners:

Fusion Application Development with Oracle JDeveoper 11g and Oracle ADF

Validation

Validation Event Points


Browser Client side validations

Used for immediate feedback.

Faces Validators Backing Bean Validations

Useful when ADF BC is not used.

ADF Model Validators

ADF BC Validations

Final line of defense.

Handling Validation Exceptions


Default behavior:
Exceptions bundled and returned to client If posted, transactions are rolled back Error message(s) displayed on JSF page

You can change default behavior by:


Creating custom exception handler Changing how lifecycle reports exceptions Customize page exception handling

JavaServer Faces Validators


Validation can be performed through
Separate validator components (classes), which provide a high degree of reusability Backing bean code
Simpler to understand as code is co-located with the subject But not reusable

JSF RI provides default validator components


No client-side validation code generated (such as JavaScript) Multiple validators can be used on one input item

Using ADF Faces Validation


ADF Faces validation:
Provides client-side validation No server round trip needed Types of ADF Faces validation:
Component Default

Using ADF Faces Component Validation


ADF Faces component validation:
Is implemented by setting certain component attribute values Can include error messages for required attribute Messages can use parameters

Das könnte Ihnen auch gefallen