15 Component Events

Embed Size (px)

Citation preview

  • 8/3/2019 15 Component Events

    1/16

    Section 15

    ADF Faces Component Events

    and Validation

    15

  • 8/3/2019 15 Component Events

    2/16

    Using Event Listeners

    Ive been clicked!

    Does anyone care?YesIm listening!

    Now Ill get to work

    Event Source

    Event Object

    Event Listener

  • 8/3/2019 15 Component Events

    3/16

    Responding to Action Events

    Command components raise action events.

    Code to respond to the action event can be in thebacking bean or external class.

    Stub code is generated by JDeveloper ondemand.

    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.

  • 8/3/2019 15 Component Events

    4/16

    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.

  • 8/3/2019 15 Component Events

    5/16

    Using Action Listeners

    Action listeners:

    Contain code to respondto an action

    Do not return a value

    Execute after valuechange listeners

    Action methods:

    Are used for navigation

    Return a String outcome

    Execute last

    Action listeners differ from action methods:

    Both can be initiated bythe same action, such as

    a button click.

  • 8/3/2019 15 Component Events

    6/16

    Value Change Events

    Input components raise value change events.

    Code for the value change listener can be in thebacking 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 InvokeApplication phase of the life cycle.

    Value change events fire before action events.

  • 8/3/2019 15 Component Events

    7/16

    Listening for Value Change Events

    Select the input component in the visual editor.

    Edit the valueChangeListener property and select abean 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 valueChangeListenerproperty in the page source

    Add your code.

  • 8/3/2019 15 Component Events

    8/16

    Event and Listener Execution Order

    The order in which the events and listeners fire is:

    1. Validator (managed bean method that performs validationon 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 alogical outcomeString that is usedin navigation)

  • 8/3/2019 15 Component Events

    9/16

    ADF Faces Enhanced Event

    Handling

    ADF Faces adds to JSF event handling by

    providing:

    Partial page rendering (PPR)

    JavaScript

  • 8/3/2019 15 Component Events

    10/16

    Other ADF Faces Events

    Property Inspector of ADF Faces components

    displays appropriate event listeners:

  • 8/3/2019 15 Component Events

    11/16

    Validation

    Fusion Application Development with

    Oracle JDeveoper 11g and Oracle ADF

  • 8/3/2019 15 Component Events

    12/16

    Validation Event PointsBrowser

    Client side validations

    Faces Validators

    Backing Bean

    Validations

    ADF Model Validators

    ADF BC Validations

    Used for immediate feedback.

    Useful when ADF BC is not used.

    Final line of defense.

  • 8/3/2019 15 Component Events

    13/16

    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 reportsexceptions

    Customize page exception handling

  • 8/3/2019 15 Component Events

    14/16

    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

  • 8/3/2019 15 Component Events

    15/16

    Using ADF Faces Validation

    ADF Faces validation:

    Provides client-side validation

    No server round trip needed

    Types of ADF Faces validation:

    Component

    Default

  • 8/3/2019 15 Component Events

    16/16

    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