Java
  Home arrow Java arrow Page 3 - Introduction to JavaServer Faces, Part 1
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? 
JAVA

Introduction to JavaServer Faces, Part 1
By: McGraw-Hill/Osborne
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 62
    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:
      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 1 - Using an Application Configuration File
    ( Page 3 of 9 )

    You can easily configure a JSF application via an application configuration file. In this file, you can register JavaBeans used in the application, define the program-control flow by specifying page-navigation rules, register custom components, and perform other configuration tasks.

    The application configuration file is an XML file and can be declared in several places. The easiest way to use this file is to put it in the WEB-INF directory and call it faces-config.xml.

    The root element of an application configuration file is faces-config. Here is the skeleton of an application configuration file:


    <?xml version="1.0"? >
    <!DOCTYPE faces-config PUBLIC
      
    "-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.0//EN"
      
    "http://java.sun.com/dtd/web-facesconfig_1_0.dtd">
     
    <
    faces-config>
    </faces-config>

    There are a number of aspects of a JSF application that can be configured in the application configuration file. Here, we will focus on how to register JavaBeans (as used in the examples later in this chapter). The application configuration file is explained in detail in Chapter 15.

    In a JSP page, you can use the jsp:useBean action to tell the JSP container that you are using the JavaBean class specified in the class attribute of the jsp:useBean action, such as the following:


    <jsp:useBean id="numberBean" class="ch02.NumberBean"
    scope
    ="session" />



    This tells the Web container to load the JavaBean class and create an instance of it when the JSP page is called. The jsp:useBean action needs to be declared in only one page, and it will be usable in all the JSP pages in the same application. A JSF application allows you to do this instead of registering a JavaBean in the application configuration file.

    However, there is a drawback when using <jsp:useBean>. If a page other than the one containing the jsp:useBean action is called before the page that does use the element is called, the Web container will throw an exception. This is because the other page is trying to use a JavaBean that has not been created. If you register the JavaBean in the application configuration file, you will not have this problem.

    For each JavaBean you want to register in the application configuration file, you use the managed-bean tag inside the faces-config element. Inside the managed-bean element, you have the following subelements:

    • The managed-bean-name tag defines a name to refer to the JavaBean from a JSP page.
    • The managed-bean-class element specifies the JavaBean class.
    • The managed-bean-scope element defines the scope of the JavaBean.

    Here is an example of a managed-bean element:


    <managed-bean>
      
    <managed-bean-name>myBean</managed-bean-name>
      
    <managed-bean-class>myPackage.MyBean</managed-bean-class>
      
    <managed-bean-scope>session</managed-bean-scope>
    </managed-bean>



    The managed-bean element in this example is of type myPackage.MyBean and can be referred to as MyBean from any JSP page in the JSF application. The scope of the bean is session, meaning that an instance of this bean is created at the beginning of a user session. The managed-bean element will be explained further in Chapter 3.

    Later in this chapter, in the “Creating the Page Navigation Example” section, you will see how to use an application configuration file to define page-navigation rules in a JSF application with many pages.

    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 (JSF)," where we learn about JSP, JavaBeans, and Model 2. 
    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 3 Hosted by Hostway
    Stay green...Green IT