JavaBeat
Search JavaBeat

JAVABEAT
home
articles
tips
QnA
Books
forums
ARTICLE TOPICS
All Articles
Java 5.0
Java 6.0
EJB 3.0
JCA
Struts
JSF
Spring
Groovy
JBoss Seam
Hibernate
Eclipse
JavaFx
Google Guice
J2ME
GWT
WebServices
AJAX
ARCHIVE
2007 | 12 11 10 09 08 07 06 05 04 03
2008 | 07 06 05 04 03 02 01
CERTIFICATION KITS
350 SCJP 1.5 Mock Exams
400 SCJP 1.6 Mock Exams
300 SCWCD 5.0 Mock Exams
300 SCBCD 5.0 Mock Exams
Enter email address:

Latest JavaBeat Articles Delivered by FeedBurner
OUR NETWORK
javabeat
planetoss
Sponsors
Java Jobs eCommerce software Get Ubuntu 8.04 Get FireFox 3.0  

Pages : 1 2

Event Driven Programming with JSF

Author : Raja
Date : Sat Nov 10th, 2007
Topic : jsf  
Enter email address:

Latest JavaBeat Articles Delivered

1) Introduction

This article discusses theories and concepts related to JSF Event Model. It details the supporting high level classes and interfaces that are involved in JSF Event Handling Mechanism. The logical categorization of JSF Events is also explained along with code snippets. Then, the tags available in the core JSF Framework are also discussed. This article doesn't provide an introduction so first-time readers of JSF are advised to read Introduction to Java Server Faces in JavaBeat before beginning this article.

2) JSF Event Model

2.1) Introduction

The model that JSF implements for handling Events is based on the standards defined in Java Beans Specification. The basic model goes like this. JSF User Interface Components are sources that can emit some kind of signals based on user actions. These signals are often termed as Events. Applications who want to process the Events can attach any number of Event Listeners to Event Sources. This simple model is also followed in Swing Components. However, the difference here is, the Event Sources (i.e, the UI Components) reside in the Client whereas the Listeners (Application Logic that does something in response to Events) will reside on the Server.

2.2) Event Classes

The classes/interfaces related to JSF Events are contained in the package 'javax.faces.event'. All Events (standard Events or User-defined Events) in JSF should extend the javax.faces.event.FacesEvent. The constructor for this class has an argument of type UIComponent which specifies for which UI Component the Event is for.


UIComponent someComponent = new UIComponent();
MyFacesEvent event = new MyFacesEvent(someComponent);

UIComponent sourceCompoenent = event.getComponent();

If the above code, the source component that generated a particular Event can be obtained by calling the method event.getComponent(). This class has a method called queue() which is used to queue the Event at the end of the current request processing life-cycle. If we want the Event to be queued and occur at a particular request processing phase, then this can be achieved by the following lines of code,


MyFacesEvent event = new MyFacesEvent();
event.setPhaseId(PhaseId.PROCESS_VALIDATIONS);

In the above code, the event MyFacesEvent will occur at the end of the 'Process Validations' life-cycle phase.

JSF defines two concrete set of Events namely ActionEvent and ValueChangeEvent and they both extend the base Event class FacesEvent. They are discussed in greater depth in the subsequent sections.

2.3) Listener Classes

There is a corresponding Listener Class for each type of Event in JSF. For example, consider the case of ActionEvent, in which there exists an equivalent Listener class called ActionListener. Same is the case of ValueChangeEvent, in which case the corresponding Listener class is ValueChangeListener.

The JavaBeans Specification mandates the support for the following methods for registering a Listener to a particular Event. For example, if the Event name is MyCustomEvent and the corresponding Listener class is MyCustomListener and we want this Event to happen for a component called MyCustomComponent, then the following methods shall be defined in the MyCustomComponent class for registering the Listeners.


public void addMyCustomListener(MyCustomListener listener)

public void removeMyCustomListener(MyCustomListener listener)

public MyCustomListener[] getMyCustomListeners()

 
Pages : 1 2
 

Sponsors
Webmaster Hosting Forum
Java Jobs
MyVideoLib
India News
Internet Advances
Latest QnA
SCJD Tips
When we start a thread by applying start() method on it ,how does it knows that to execute run()method?
About Wrapper class in Java
How to configure weblogic 7.0 in MyEclipse?
Static Block and Static Initializer in Java

JavaBeat Media (2004-2008), India
javabeat | planetoss | links directory | advertise
Copyright (2004 - 2008), JavaBeat