Home arrow Java & J2EE arrow Page 6 - Introduction to JavaServer Faces, Part 1

Creating the Event Listener and Component Tree Example - Java

This chapter gently introduces the JavaServer Faces technology. More importantly, it teaches you how to write your first JSF application to get a feel for how this great technology works.  In addition to the sample chapters, this chapter prepares you for the next chapters by introducing the JSF Application Programming Interface (API) and the Application Configuration file. This excerpt comes from chapter two of JavaServer Faces Programming, by Budi Kurniawan (McGraw-Hill/Osborne, ISBN 0-07-222983-7, 2004).

TABLE OF CONTENTS:
  1. Introduction to JavaServer Faces, Part 1
  2. Understanding the Request Processing Lifecycle Phases
  3. Using an Application Configuration File
  4. Writing a JSF Application
  5. Writing JavaBeans and Event Listeners
  6. Creating the Event Listener and Component Tree Example
  7. Creating the Directory Structure
  8. Writing the Object Model for the Listener and Component Tree Example
  9. Defining Taglib Directives
By: McGraw-Hill/Osborne
Rating: starstarstarstarstar / 74
March 08, 2004

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

The example presented in this section illustrates the process of developing a simple JSF application. It demonstrates how to write a JSF application with an event listener that is executed when the user clicks a button. The event listener simply prints the names of the components in the component tree.

The application consists of a JSP page that has a form with two input fields to accept two numbers and print the result of the addition of the two numbers. There is also a button that, when clicked, fires an ActionEvent and causes an event listener to be executed.

The page has five user interface (UI) components: a UIForm component, two UIInput components, a UIOutput component, and a UICommand component (these are described in the previous section). The UIInput components and the UIOutput component are bound to a JavaBean that stores the two input values and contains the logic of the addition.

As explained earlier in this chapter, the request processing lifecycle always begins with the Reconstitute Component Tree phase. In this phase, the Lifecycle object builds the component tree representing the requested page. This example shows how a component tree looks conceptually. To be able to draw the tree, you need to create an event listener that will be called during one of the process event steps in the request processing lifecycle.

The application consists of the following:

  • A JSP page named adder.jsp
  • A NumberBean JavaBean for storing user data
  • An action listener called MyActionListener
  • A deployment descriptor (web.xml)
  • An application configuration file for registering the JavaBean

For your JSF application to work, it needs a set of .jar files containing the JSF reference implementation and other libraries. See the “Introduction” of this book for the list of all libraries you need to include in your JSF application.

NOTE Don’t worry if you don’t fully understand the code used in the application examples in this chapter. The code will be explained in later chapters.

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 part 2 of "Introduction to JavaServer Faces," where we learn about JSP, JavaBeans, and Model 2. 
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: