JSF Tutorial
An Introduction to JavaServer Faces
Plus Apache MyFaces Extensions
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.1.5.
The course is usually taught on-site at customer locations, but
servlet, JSP,
Ajax, 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 training course page. To inquire about a customized training course at your location, please contact Marty at hall@coreservlets.com.
Courses on servlets, JSP, Ajax, Struts, Hibernate, Java 5, Java 6, and Ruby/Rails also available.
Available free for university faculty:
The original PowerPoint versions of the
tutorials are available free for university faculty in certain cases.
Please see
instructor usage rules for details.
View
PDF of Introducing JSF section.
Source Code:
-
jsf-blank-myfaces-app.zip
Blank Web app to use as a starting point for JSF applications.
Apache MyFaces version, bundled as a normal Web application
(as opposed to an Eclipse project as below).
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.
-
jsf-blank-myfaces-eclipse.zip
Same as above, but bundled as an
Eclipse project.
-
jsf-blank-myfaces-with-extensions-app.zip
Blank Web app to use as a starting point for JSF applications.
Apache MyFaces version, bundled as a normal Web application
(as opposed to an Eclipse project as below).
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, file upload, and more.
-
jsf-blank-myfaces-with-extensions-eclipse.zip
Same as above, but bundled as an
Eclipse project.
-
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 Facelets, Tiles, and the MyFaces components, the examples in
this tutorial run equally well on top of either the MyFaces or Sun
RI base.
Topics:
- 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
View
PDF of Controlling Page Navigation section.
Source Code:
Topics:
- JSF flow of control
- The basic steps in using JSF
- Static navigation
- Dynamic navigation
View
PDF of Handling Request Parameters with Managed Beans section.
Source Code:
Topics:
- Using beans to represent request parameters
- Declaring beans in faces-config.xml
- Outputting bean properties
- Standard JSF approach
- JSP 2.0 expression language
View
PDF of Using the JSF Expression Language section.
Source Code:
Topics:
- Motivating use of the expression language
- Comparing to the JSP 2.0 EL
- Accessing bean properties
- Submitting bean properties
- Expressions in output values
- Expressions in submission values
- Expressions for action controllers
- Accessing collection elements
- Using implicit objects and operators
View
PDF of Using Properties Files section.
Source Code:
Topics:
- Loading properties files
- Simple messages
- Parameterized messages
- Internationalized messages
View
PDF of Handling Events section.
Source Code:
Topics:
- 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
View
PDF of Building Input Forms with the h: Library section.
Source Code:
Topics:
- The most common HTML elements
- Shared attributes
- Implied attributes
- Elements that can invoke action controllers/listeners
- Elements that can invoke value change listeners
- Elements that display lists of items
View
PDF of Validating User Input and Redisplaying Incomplete Forms section.
Source Code:
Topics:
- Manual validation
- Implicit automatic validation
- Explicit validation
- Defining your own validation methods
- Creating custom validators
View
PDF of Accessing Databases with JDBC section.
Source Code:
- 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:
- 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
View
PDF of Introducing JSF section.
Source Code:
The database-related examples assume you have set up the
Northwind database as described in
the JDBC notes.
Topics:
- Motivation
- Basic syntax
- Defining table headings
- Formatting tables with style sheets
- Displaying database tables
View
PDF of Using the Apache MyFaces Components section.
Source Code:
-
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:
- Popular Apache component libraries
- 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
View
PDF of Ajax4jsf section.
Source Code:
Topics:
- Ajax motivation
- Installation
- Main Ajax4jsf Elements
- a4j:commandButton
- a4j:commandLink
- a4j:poll
- a4j:support
- Limitations on use of h:outputText with Ajax4jsf
- Other Ajax Toolkits
Note: for more details on Ajax, please see
the Ajax and GWT (Google Web Toolkit) tutorial.
View
PDF of Developing Custom Tag Libraries: The Basics section.
Source Code:
Download tags code
Topics:
- 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
View
PDF of Developing Custom Tag Libraries: Advanced Topics section.
Source Code:
Download tags code
Topics:
- 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
View
PDF of Developing Custom Components section.
Source Code:
Topics:
- Simple output-only components
- Components that accept attributes
- Components that accept input
View
PDF of Page Templating with Facelets section.
Source Code:
Topics:
- Simple output-only components
- Components that accept attributes
- Components that accept input
View
PDF of Using (Struts) Tiles with JSF section.
Source Code:
- 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:
- 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
View
PDF of Using the JSP Standard Tag Library (JSTL) with JSF section.
Source Code:
Topics:
- 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
- JSF home page
- JSF download page
- Onsite JSF Training Courses
Personally developed and
taught by the author of the best-selling Sun Press books
Core Servlets and JavaServer Pages, More Servlets and JavaServer Pages,
Core Web Programming, and this JavaServer Faces tutorial.
- JSF Books (in order of my personal preference)
-
JSF Section of Sun J2EE 1.4 tutorial
- JSF API Javadocs
- JSF tag library docs
- jsf-config.xml annotated DTD
- Sun's JSF FAQ
- The JavaServer Faces Forum
- Servlet, JSP, and Struts Programming Resources (Links)
- Servlet, JSP, and Struts Course Materials (PDF)
- Basic Java Programming Resources (Links)
- Servlet, JSP, Struts, JSF, and Java Programming Short Courses
|