JSF Tutorial

An Introduction to JavaServer Faces
Plus Apache MyFaces Extensions

1: Introducing JSF: Overview, Pros, Cons, Installation, and Setup 2: Controlling Page Navigation
3: Handling Request Parameters with Managed Beans 4: Using the JSF Expression Language
5: Using Resource Bundles (Properties Files) in JSF 6: Handling Events
7: Building Input Forms with the h: Library 8: Validating User Input and Redisplaying Incomplete Forms
9: Accessing Databases with JDBC 10: Displaying Data Tables
11: Using MyFaces Custom Components
and Validators (Tomahawk)
12: Developing Custom Tag Libraries:
The Basics
13: Developing Custom Tag Libraries:
Advanced Topics
14: Developing Custom Components
15: Using (Struts) Tiles with JSF 16: Using the JSP Standard Tag Library (JSTL) with JSF
More Info on JavaServer Faces and Related Java Technologies JSF Training Courses


Training Courses: JSP, Servlets, Jakarta Struts, JSF, AJAX, & Java 5

Programming with
Servlets & JSP
June 20-23, 2006

Jakarta Struts &
Advanced JSP
June 26-30, 2006

JavaServer Faces (JSF)
& Apache MyFaces
July 11-13, 2006

Customized Onsite Training
Courses at Your Location
Dates Flexible. Any country


This tutorial is derived from Marty Hall's world-renowned live JSF training course. Note that the course (and this tutorial) now covers Apache MyFaces 1.4. The course is usually taught on-site at customer locations, but servlet, JSP, Jakarta Struts, and JSF training courses at public venues are periodically scheduled for people with too few developers for an onsite course. For descriptions of the various other courses that are available, please see the servlet, JSP, Jakarta Struts, and JSF training course page. To inquire about a customized training course at your location, please contact Marty at [email protected]. Courses on servlets, JSP, AJAX, Shale, Hibernate, and Java programming also available.

Note that the original PowerPoint versions of the tutorials are available free for university faculty in certain cases. Please see instructor usage rules for details.

Section 1: Introducing JSF

Other Free Tutorials & Training Materials
  • Intermediate servlet and JSP tutorials & training materials
  • Advanced servlet and JSP tutorials & training materials
  • Jakarta Struts tutorials & training materials
  • Apache Tomcat tutorial
  • JSP and servlet programming resources
  • Chinese JSP & servlet training materials
  • Japanese JSP & servlet training materials
  • Training materials on Java programming
  • Java programming resources
  • Live JSP, servlet, Struts and JSF training courses
  • PDF for this Section of JSF Tutorial
    • 01-JSF-Intro.pdf.
      Freely available for personal learning. Do not redistribute.
  • Source Code for Examples in this Section of JSF Tutorial
    • jsf-blank-myfaces.zip.
      Blank Web app to use as a starting point for JSF applications. Apache MyFaces version. Has all necessary JAR files in WEB-INF/lib, all required settings in WEB-INF/web.xml, and a blank WEB-INF/faces-config.xml file. In addition to the standard JSF features, this Web app includes JAR files and settings for the standard Apache MyFaces extensions: Tomahawk (MyFaces custom components and validators), Tiles, Portlets, file upload, and more.
    • jsf-blank-Sun-RI.zip.
      Blank Web app to use as a starting point for JSF applications. Sun Reference Implementation (RI) version. Has all necessary JAR files in WEB-INF/lib, all required settings in WEB-INF/web.xml, and a blank WEB-INF/faces-config.xml file. Except for the sections on Tiles and the MyFaces components, the examples in this tutorial run equally well on top of either the MyFaces or Sun RI base.
    • jsf-blank-myfaces-minimal.zip.
      Blank Web app to use as a starting point for JSF applications. Does not include the MyFaces extensions.
  • Topics?in?this?Section
    • Understanding JSF
      • Different views of JSF
      • Comparing JSF to standard servlet/JSP technology
        • Pros
        • Cons
      • Comparing JSF to Apache Struts
        • Pros
        • Cons
    • Setting Up JSF
      • Downloading and configuring JSF
        • Apache MyFaces
        • Sun Reference Implementation
      • Testing JSF
      • Setting up JSF applications
      • Accessing JSF documentation
        • Generic
        • Specific to Apache MyFaces

Section 2: Controlling Page Navigation

  • PDF for this Section of JSF Tutorial
    • 02-Page-Navigation.pdf.
      Freely available for personal learning. Do not redistribute.
  • Source Code for Examples in this Section of JSF Tutorial
    • jsf-test.zip.
      Web application used for the examples in this section. Note that the JAR files have been removed from WEB-INF/lib to dramatically decrease the download size. Copy the JAR files from the WEB-INF/lib directory of the jsf-blank Web app (either the Apache MyFaces version or the Sun RI version) to the WEB-INF/lib directory of this app, or put the JAR files in your server's location for shared JAR files.
    • jsf-test-full.zip.
      Full Web app used for the examples in this section. Apache MyFaces version. Please note that, since this file repeats the large JAR files in WEB-INF/lib, downloading the full version is a waste of time if you already have jsf-blank.
  • Topics?in?this?Section
    • JSF flow of control
    • The basic steps in using JSF
    • Static navigation
      • One result mapping
    • Dynamic navigation
      • Multiple result mappings
Section 3: Handling Request Parameters with Managed Beans

  • PDF for this Section of JSF Tutorial
    • 03-Managed-Beans.pdf.
      Freely available for personal learning. Do not redistribute.
  • Source Code for Examples in this Section of JSF Tutorial
    • jsf-test.zip.
      Web application used for the examples in this section. Note that the JAR files have been removed from WEB-INF/lib to dramatically decrease the download size. Copy the JAR files from the WEB-INF/lib directory of the jsf-blank Web app (either the Apache MyFaces version or the Sun RI version) to the WEB-INF/lib directory of this app, or put the JAR files in your server's location for shared JAR files.
    • jsf-test-full.zip.
      Full Web app used for the examples in this section. Apache MyFaces version. Please note that, since this file repeats the large JAR files in WEB-INF/lib, downloading the full version is a waste of time if you already have jsf-blank.
  • Topics?in?this?Section
    • Using beans to represent request parameters
    • Declaring beans in faces-config.xml
    • Outputting bean properties
      • Standard JSF approach
      • JSP 2.0 expression language
    • Using properties files
      • Standard prompts/strings
      • Internationalized text
JSF Tutorial Section 4: Using the JSF Expression Language

  • PDF for this Section of JSF Tutorial
    • 04-Expression-Language.pdf.
      Freely available for personal learning. Do not redistribute.
  • Source Code for Examples in this Section of JSF Tutorial
    • jsf-el.zip.
      Web application used for the examples in this section. Note that the JAR files have been removed from WEB-INF/lib to dramatically decrease the download size. Copy the JAR files from the WEB-INF/lib directory of the jsf-blank Web app (either the Apache MyFaces version or the Sun RI version) to the WEB-INF/lib directory of this app, or put the JAR files in your server's location for shared JAR files.
    • jsf-el-full.zip.
      Full Web app used for the examples in this section. Apache MyFaces version. Please note that, since this file repeats the large JAR files in WEB-INF/lib, downloading the full version is a waste of time if you already have jsf-blank.
  • Topics?in?this?Section
    • Motivating use of the expression language
      • Comparing to the JSP 2.0 EL
    • Accessing bean properties
      • Direct
      • Nested
    • Submitting bean properties
      • Expressions in output values
      • Expressions in submission values
      • Expressions for action controllers
    • Accessing collection elements
    • Using implicit objects and operators
JSF Tutorial Section 5: Using Properties Files (Resource Bundles)

  • PDF for this Section of JSF Tutorial
    • 05-Properties-Files.pdf.
      Freely available for personal learning. Do not redistribute.
  • Source Code for Examples in this Section of JSF Tutorial
    • jsf-messages.zip.
      Web application used for the examples in this section. Note that the JAR files have been removed from WEB-INF/lib to dramatically decrease the download size. Copy the JAR files from the WEB-INF/lib directory of the jsf-blank Web app (either the Apache MyFaces version or the Sun RI version) to the WEB-INF/lib directory of this app, or put the JAR files in your server's location for shared JAR files.
    • jsf-messages-full.zip.
      Full Web app used for the examples in this section. Apache MyFaces version. Please note that, since this file repeats the large JAR files in WEB-INF/lib, downloading the full version is a waste of time if you already have jsf-blank.
  • Topics?in?this?Section
    • Loading properties files
    • Simple messages
    • Parameterized messages
    • Internationalized messages
JSF Tutorial Section 6: Handling Events

  • PDF for this Section of JSF Tutorial
    • 06-Event-Handling.pdf.
      Freely available for personal learning. Do not redistribute.
  • Source Code for Examples in this Section of JSF Tutorial
    • jobs.zip.
      Web application used for the examples in this section. Note that the JAR files have been removed from WEB-INF/lib to dramatically decrease the download size. Copy the JAR files from the WEB-INF/lib directory of the jsf-blank Web app (either the Apache MyFaces version or the Sun RI version) to the WEB-INF/lib directory of this app, or put the JAR files in your server's location for shared JAR files.
    • jobs-full.zip.
      Full Web app used for the examples in this section. Apache MyFaces version. Please note that, since this file repeats the large JAR files in WEB-INF/lib, downloading the full version is a waste of time if you already have jsf-blank.
  • Topics?in?this?Section
    • Comparing action controllers to event listeners
    • Action listeners
    • Value change listeners
    • Using JavaScript to submit form
      • Browser incompatibilities
    • Combining action listeners and action controllers in the same GUI element
JSF Tutorial Section 7: Building Input Forms with the h: Library

  • PDF for this Section of JSF Tutorial
    • 07-HTML-Library.pdf.
      Freely available for personal learning. Do not redistribute.
  • Source Code for Examples in this Section of JSF Tutorial
    • jsf-blank.
      Blank Web app to use as a starting point for JSF applications.
  • Topics?in?this?Section
    • The most common HTML elements
    • Shared attributes
    • Implied attributes
    • Custom components with the Sun Reference Implementation
      • See next section for custom MyFaces components
JSF Tutorial Section 8: Validating User Input and Redisplaying Incomplete Forms

  • PDF for this Section of JSF Tutorial
    • 08-Validation.pdf.
      Freely available for personal learning. Do not redistribute.
  • Source Code for Examples in this Section of JSF Tutorial
    • bids.zip.
      Web application used for the examples in this section. Note that the JAR files have been removed from WEB-INF/lib to dramatically decrease the download size. Copy the JAR files from the WEB-INF/lib directory of the jsf-blank Web app (either the Apache MyFaces version or the Sun RI version) to the WEB-INF/lib directory of this app, or put the JAR files in your server's location for shared JAR files. Be sure to use the extended MyFaces version of jsf-blank if you want to use the MyFaces-specific validators.
    • bids-full.zip.
      Full Web app used for the examples in this section. Apache MyFaces version. Please note that, since this file repeats the large JAR files in WEB-INF/lib, downloading the full version is a waste of time if you already have jsf-blank.
  • Topics?in?this?Section
    • Manual validation
    • Implicit automatic validation
    • Explicit validation
    • Defining your own validation methods
    • Creating custom validators
JSF Tutorial Section 9: Accessing Databases with JDBC

  • PDF for this Section of JSF Tutorial
    • 09-JDBC.pdf.
      Freely available for personal learning. Do not redistribute.
  • Source Code for Examples in this Section of JSF Tutorial
    • NorthwindTest.java.
      Standalone application to test the Northwind database. Only works if you have set up the Northwind database as described in the JDBC notes.
    • NorthwindServlet2.java.
      Servlet to test the Northwind database. Uses the driver and connection explicitly. Only works if you have set up the Northwind database as described in the JDBC notes.
    • server.xml.
      Tomcat configuration file to register the Northwind database as a data source. Only works if you have set up the Northwind database as described in the JDBC notes. Specific to Tomcat version!
    • NorthwindServlet3.java.
      Servlet to test the Northwind database. Uses JNDI to get the connection. Only works if you have registered the data source and set up the Northwind database as described in the JDBC notes.
  • Topics?in?this?Section
    • Overview of JDBC technology
    • JDBC drivers
    • Seven basic steps in using JDBC
    • Using JNDI with JDBC
    • Retrieving data from a ResultSet
    • Using prepared and callable statements
    • Handling SQL exceptions
    • Submitting multiple statements as a transaction
JSF Tutorial Section 10: Displaying Data Tables

  • PDF for this Section of JSF Tutorial
    • 10-Data-Tables.pdf.
      Freely available for personal learning. Do not redistribute.
  • Source Code for Examples in this Section of JSF Tutorial The database-related examples assume you have set up the Northwind database as described in the JDBC notes.
    • tables.zip.
      Web application used for the examples in this section. Note that the JAR files have been removed from WEB-INF/lib to dramatically decrease the download size. Copy the JAR files from the WEB-INF/lib directory of the jsf-blank Web app (either the Apache MyFaces version or the Sun RI version) to the WEB-INF/lib directory of this app, or put the JAR files in your server's location for shared JAR files. Be sure to use the extended MyFaces version of jsf-blank if you want to use the MyFaces-specific validators.
    • tables-full.zip.
      Full Web app used for the examples in this section. Apache MyFaces version. Please note that, since this file repeats the large JAR files in WEB-INF/lib, downloading the full version is a waste of time if you already have jsf-blank.
  • Topics?in?this?Section
    • Motivation
    • Basic syntax
    • Defining table headings
    • Formatting tables with style sheets
    • Displaying database tables
JSF Tutorial Section 11: Using the Apache MyFaces Components (Tomahawk)

  • PDF for this Section of JSF Tutorial
    • 11-MyFaces-Components.pdf.
      Freely available for personal learning. Do not redistribute.
  • Source Code for Examples in this Section of JSF Tutorial
    • myfaces-components.zip.
      Web application used for the examples in this section. This is the complete version, including all JAR files and web.xml settings. Specific to Apache MyFaces. If you want to start with a blank Web app and add in MyFaces extended components (Tomahawk), be sure to start with the full (not minimal) version of the Apache MyFaces version of jsf-blank.
  • Topics?in?this?Section
    • Popular Apache component libraries
      • Tomahawk
      • Tobago
      • Trinidad
    • Getting the Tomahawk components
    • Configuring MyFaces to use Tomahawk
    • Sample components
      • Date input
      • Tabbed panes
      • Popups
      • Data lists
      • Tables with column flow
    • Sample validators
      • Regular expressions
      • Email addresses
      • Credit cards
      • Equality
    • Overview of other components
JSF Tutorial Section 12: Developing Custom Tag Libraries: The Basics

  • PDF for this Section of JSF Tutorial
    • 12-Basic-Custom-Tags.pdf.
      Freely available for personal learning. Do not redistribute.
  • Source Code for Examples in this Section of JSF Tutorial Tags code can be downloaded here.
  • Topics?in?this?Section
    • Java-based tags
      • Components of a tag library
      • Basic tags
      • Tags that use attributes
      • Tags that use body content
      • Tags that optionally use body content
    • JSP-based tags (tag files)
      • Components of a tag library
      • Basic tags
      • Tags that use attributes
      • Tags that use body content
JSF Tutorial Section 13: Developing Custom Tag Libraries: Advanced Topics

  • PDF for this Section of JSF Tutorial
    • 13-Advanced-Custom-Tags.pdf.
      Freely available for personal learning. Do not redistribute.
  • Source Code for Examples in this Section of JSF Tutorial Tags code can be downloaded here.
  • Topics?in?this?Section
    • Manipulating the tag body
    • Tags with dynamic attribute values
    • Tags with complex objects for attributes
    • Looping tags
    • Nested tags
    • Using SAX and TagLibraryValidator to validate tag library syntax
JSF Tutorial Section 14: Developing Custom Components

  • PDF for this Section of JSF Tutorial
    • 14-Custom-Components.pdf.
      Freely available for personal learning. Do not redistribute.
  • Source Code for Examples in this Section of JSF Tutorial
    • custom-components.zip.
      Web application used for the examples in this section. Note that the JAR files have been removed from WEB-INF/lib to dramatically decrease the download size. Copy the JAR files from the WEB-INF/lib directory of the jsf-blank Web app (either the Apache MyFaces version or the Sun RI version) to the WEB-INF/lib directory of this app, or put the JAR files in your server's location for shared JAR files.
    • custom-components-full.zip.
      Full Web app used for the examples in this section. Apache MyFaces version. Please note that, since this file repeats the large JAR files in WEB-INF/lib, downloading the full version is a waste of time if you already have jsf-blank.
  • Topics?in?this?Section
    • Simple output-only components
    • Components that accept attributes
    • Components that accept input
JSF Tutorial Section 15: Using (Struts) Tiles with JSF

  • PDF for this Section of JSF Tutorial
    • 15-JSF-and-Tiles.pdf.
      Freely available for personal learning. Do not redistribute.
  • Source Code for Examples in this Section of JSF Tutorial
    • e-boats.zip.
      First Web application used for the examples in this section. This is the complete version, including all JAR files and web.xml settings. The deployed JAR files are for Apache MyFaces 1.1, but the basic code can also run in the Sun Reference Implementation if you include struts.jar.
    • e-boats2.zip.
      Second Web application used for the examples in this section. This is the complete version, including all JAR files and web.xml settings. Specific to Apache MyFaces.
  • Topics?in?this?Section
    • Tiles motivations
    • Setting up JSF (any implementation) for simple Tiles
    • Tiles basics
      • Sketch out desired layout
      • Make template file that represents layout
      • Create JSP pages that define layout pieces
      • Create JSP pages that populate layout
    • Setting up MyFaces for Tiles definitions
    • Using Tiles definitions file
JSF Tutorial Section 16: Using the JSP Standard Tag Library (JSTL) with JSF

  • PDF for this Section of JSF Tutorial
    • 16-JSF-and-JSTL.pdf.
      Freely available for personal learning. Do not redistribute.
  • Topics?in?this?Section
    • Obtaining JSTL documentation and code
    • The JSTL Expression Language
    • Looping Tags
      • Looping a certain number of times
      • Looping over data structures
    • Conditional Evaluation Tags
      • Single choice
      • Multiple choices
    • Database Access Tags
    • Other Tags
More Information about JavaServer Faces and Related Technologies




Hosted by kattare.com. Expert Tomcat, Resin, and JBoss hosting.