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

Writing JavaBeans and Event Listeners - 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).

  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



Writing JavaBeans

As noted earlier, you can bind a component to a JavaBean. In this case, the componentís local value will be copied to the JavaBeanís property if the local value is valid. To bind a component to a JavaBeanís property, you use the valueRef attribute in the custom tag representing the component. For example, to bind a UIOutput component so that it can retrieve its value from the result property of a JavaBean called testingBean, use the following:

<h:output_text valueRef="testingBean.result"/>
<h:output_text valueRef="testingBean.result"></h:output_text>

Writing Event Listeners

Because JSF applications are event-driven, you need to write event listeners to determine how your applications will behave. You need to register any event listener that you want to be notified when an event is triggered by a component. To register an ActionListener with a component such as a UICommand, use the action_listener tag of the Core custom tag library inside the custom tag representing the component:

<h:command_button id="submitButton" label="Add"
="submit" >
<f:action_listener type="ch02a.MyActionListener" />
<h:command_button id=submitButton commandName="submit" label="Add"><f:action_listener type="ch02a.MyActionListener"></f:action_listener></h:command_button>

You must also write your listener class by implementing the javax.faces.event. ActionListener interface or the javax.faces.event.ValueChangedListener interfaces.

Events and listeners are discussed in more detail in Chapter 7.

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


- 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: