Java
  Home arrow Java arrow Page 5 - Introduction to JavaServer Faces, Part...
Dev Shed Forums 
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Sun Developer Network 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Moblin 
JMSL Numerical Library 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
JAVA

Introduction to JavaServer Faces, Part 1
By: McGraw-Hill/Osborne
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 52
    2004-03-08

    Table of Contents:
  • Introduction to JavaServer Faces, Part 1
  • Understanding the Request Processing Lifecycle Phases
  • Using an Application Configuration File
  • Writing a JSF Application
  • Writing JavaBeans and Event Listeners
  • Creating the Event Listener and Component Tree Example
  • Creating the Directory Structure
  • Writing the Object Model for the Listener and Component Tree Example
  • Defining Taglib Directives

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Introduction to JavaServer Faces, Part 1 - Writing JavaBeans and Event Listeners


    (Page 5 of 9 )

    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"
      commandName
    ="submit" >
      
    <f:action_listener type="ch02a.MyActionListener" />
    </h:command_button>
    <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 Articles
    More By McGraw-Hill/Osborne


     

       

    JAVA ARTICLES

    - New Object Initialization in Java
    - Adding Images With iTextSharp
    - Adding Columns With iTextSharp
    - Creating Simple PDF Files With iTextSharp
    - The Spring Framework: Understanding IoC
    - Introducing the Spring Framework
    - Java Classes
    - Completing the Syntactic Comparison of Java ...
    - Syntactic Comparison of Java and C/C++
    - Java Statements
    - Conditionals, Expressions and Other Java Ope...
    - Java Operators
    - Primitive Data Types and Basic Language Rule...
    - Java and Object-Oriented Programming
    - Java Beginning Programming





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway