Java
  Home arrow Java arrow Introduction to JavaServer Faces Part 2
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
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? 
Google.com  
JAVA

Introduction to JavaServer Faces Part 2
By: McGraw-Hill/Osborne
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 20
    2004-03-15


    Table of Contents:
  • Introduction to JavaServer Faces Part 2
  • The Action Listener
  • Continuing With the navigateComponent Tree
  • Console Message
  • And the Message
  • Authoring the JSP Page for the Validator Example

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log 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 2
    ( Page 1 of 6 )

    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.

    Intro to JavaServer FacesWriting the ActionListener for the Listener and Component Tree Example

    The ActionListener for the command button is the most interesting part of this JSF application. It demonstrates how an event causes a listener to be executed. The listener simply prints messages to the console. However, it shows important information such as the hierarchy of the component tree of the JSP page from which the event was fired and the component that triggered the event. The ActionListener is shown in Listing 5.

     

    Listing 5 The ActionListener for the Command Button (MyActionListener.java)

     
    package ch02a
    import java
    .util.Iterator
    import javax
    .faces.component.UIComponent
    import javax
    .faces.context.FacesContext
    import javax
    .faces.event.ActionEvent
    import javax
    .faces.event.ActionListener
    import javax
    .faces.event.PhaseId
    import javax
    .faces.tree.Tree


    public class MyActionListener implements ActionListener 


      
    public PhaseId getPhaseId() { 
       System
    .out.println("getPhaseId called");  
       
    return PhaseId.APPLY_REQUEST_VALUES

     
     public 
    void processAction(ActionEvent event) {   
       System
    .out.println("processAction called");  
       
    // the component that triggered the action event 
       UIComponent component = event.getComponent();
       System.out.println(   
        "The id of the component that fired the action event: "   
        + component.getComponentId());   
       // the action command   
       String actionCommand = event.getActionCommand() 
       System.out.println("Action command: " + actionCommand); 


          
    FacesContext facesContext FacesContext.getCurrentInstance();
          Tree tree 
    facesContext.getTree(); 
          UIComponent root 
    tree.getRoot(); 
          System
    .out.println("----------- Component Tree ------------");
          navigateComponentTree
    (root0); 
          System
    .out.println("----------------------------------------"); 
      



       
    private void navigateComponentTree
          UIComponent component
    int level){ 
          
    // indent 
          for (int i=0; i<level; i++) 
            System.out.print(" "); 
          // print component id 
          System.out.println(component.getComponentId()); 
          Iterator children = component.getChildren(); 
          // navigate children 
          while (children.hasNext()) { 
             UIComponent child = (UIComponent) children.next();
             navigateComponentTree(child, level + 1); 
           } 
         } 


    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 Articles          >>> More By McGraw-Hill/Osborne
     

       

    JAVA ARTICLES

    - Exception Handling Techniques in Java
    - More About Multithreading in Java
    - The Basics of Multiple Threads in Java
    - Data Access Using Spring Framework JDBC
    - 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...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 6 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek