Home arrow Java & J2EE arrow Page 2 - Introduction to JavaServer Faces Part 2

The Action Listener - Java

We continue with part two of Chapter 2 of Introduction JavaServer Faces Programming, by Budi Kurniawan (McGraw-Hill/Osborne, ISBN 0-07-222983-7, 2004). This section deals with the ActionListener and Component Tree, as well as validation and navigation for your JSP pages.  This chapter prepares you for the next chapters by introducing the JSF Application Programming Interface (API) and the Application Configuration file.

TABLE OF CONTENTS:
  1. Introduction to JavaServer Faces Part 2
  2. The Action Listener
  3. Continuing With the navigateComponent Tree
  4. Console Message
  5. And the Message
  6. Authoring the JSP Page for the Validator Example
By: McGraw-Hill/Osborne
Rating: starstarstarstarstar / 23
March 15, 2004

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

An ActionListener must implement the javax.faces.event.ActionListener interface. It provides the implementations for the getPhaseId and processAction methods. The getPhaseId method must return a javax.faces.event.PhaseId, and its return value determines in which process event step of the request processing lifecycle the listener will be executed. The getPhaseId method in the ActionListener in Listing 5 returns PhaseId.APPLY_REQUEST_VALUES. This will make the ActionListener‘s processAction method be called after the Apply Request Values phase of the request processing lifecycle.

The processAction method accepts the javax.faces.event.ActionEvent object from the Lifecycle object. In the ActionListener in Listing 5, the processAction method first obtains the component that triggered the event by calling the getComponent method of the ActionEvent class, and then it prints the component identifier.


UIComponent component event.getComponent();
System
.out.println(
"The id of the component that fired the action event: "
component.getComponentId());

It then prints the action command of the ActionEvent object.


// the action command
String actionCommand = event.getActionCommand();
System.out.println("Action command: " + actionCommand);

Next, it obtains the instance of the current FacesContext and calls its getTree method to acquire the component tree (an instance of javax.faces.tree.Tree class) representing the request page.


</f:use_faces><f:use_faces>FacesContext facesContext FacesContext.getCurrentInstance();
Tree tree 
facesContext.getTree();

To get the root of the component tree, it calls the getRoot method of the Tree class.

UIComponent root tree.getRoot();

Next, it passes the root to the private method navigateComponentTree, which draws the component tree hierarchy.

navigateComponentTree(root0);

Buy this book now!Remember: This is part one of the second chapter of JavaServer Faces Programming, by Budi Kurniawan (McGraw-Hill/Osborne, ISBN 0-07-222983). Stay tuned for more helpful chapters from McGraw-Hill/Osborne.
Buy this book!



 
 
>>> More Java & J2EE Articles          >>> More By McGraw-Hill/Osborne
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

JAVA & J2EE ARTICLES

- More Java Bugs Lead to More Attacks
- Oracle's Java One Brings News, Surprises
- Oracle Patches Java Runtime Environment
- Apple Syncs Java Update with Oracle
- Spring 3.1 Java Development Framework Compat...
- Jelastic Java PaaS Availability and Pricing ...
- NetBeans 7.1 Released, Supports JavaFX 2
- SolarWinds Releases Newest Version of Java M...
- Free Monitoring Tool for Java Apps on Heroku
- Heroku Adds JCloud Platform Support, Java 7 ...
- Java SE 8 Speculation in Full Swing
- Java SE 7 Now Available
- New JVM Language and Java Reporting Tool
- Java 7 Release Update and New Eclipse Toolkit
- The Best Java Netbeans IDE Plugins

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: