Home arrow Java & J2EE arrow Introduction to JavaServer Faces, Part 3

Introduction to JavaServer Faces, Part 3

This chapter has been leading us gently through the JavaServer Faces technology. More importantly, in it, Budi teaches ushow to write an online survey application to get a feel for how this great technology works. This chapter prepares you for the next chapters by introducing the JSF Application Programming Interface (API) and the Application Configuration file. This excerpt comes from chapter two of JavaServer Faces Programming, by Budi Kurniawan (McGraw-Hill/Osborne, ISBN 0-07-222983-7, 2004).

  1. Introduction to JavaServer Faces, Part 3
  2. Wrtiting the JSP Files for the Page Navigation Example
  3. Creating the Application Configuration File for the Page Navigation Example
  4. Compiling and Running the Page Navigation Example
  5. Introducing the JSF Application Programming Interface (API)
  6. javax Packages
  7. More javax Packages
By: McGraw-Hill/Osborne
Rating: starstarstarstarstar / 21
March 22, 2004

print this article



Creating the Page Navigation Example
JavaServer FacesThis section presents another sample application, which features an online survey application with two JSP pages. What makes it different from the previous two examples is that this application has multiple pages. Its main purpose is to demonstrate how to navigate from one JSP page to another.

Like the first two applications, this application is simple. The first page displays a form that takes two input boxes, where you enter your favorite singer and favorite band. After you submit the form, the second JSP page is displayed. The second JSP page displays the values you entered into the form in the first page. It also allows you to go back to the first page by clicking a button. A JavaBean called SurveyBean is used to store the userís data.

This application requires a directory structure, deployment descriptor (the same as the ones for the previous examples, shown in Listing 1), a JavaBean, an application configuration file, and two JSP pages.

Creating the Directory Structure for the Page Navigation Example

You need to create a directory called JSPCh02c for this application. In Tomcat, you create the directory under the webapps directory. The directory structure for this application is shown in Figure 10. Notice that it has two JSP pages: page1.jsp and page2.jsp. Also, the SurveyBean class resides under the WEB-INF/classes directory. As usual, you must copy all required libraries to the WEB-INF/lib directory.

Creating the SurveyBean
Your application needs a JavaBean to store data. This bean is called SurveyBean, and it can be found in the SurveyBean.java file in the ch02c package. It is shown in Listing 7

JSF directory structure

Figure 10 The directory structure of the page navigation example 

Listing 7 The SurveyBean

package ch02c
class SurveyBean 
   String favSinger 
   String favBand 
public void setFavSinger(String favSinger) { 
.favSinger favSinger

public String getFavSinger() { 
return favSinger

public void setFavBand(String favBand) { 
.favBand favBand
} public String getFavBand() { 
return favBand
<?xml:namespace prefix /><f:use_faces>}

There is nothing special in the SurveyBean class. It has two properties, favSinger and favBand, and accessors and mutators (get and set methods) for the properties.

Buy this book now!Remember: This is part three of the second chapter of JavaServer Faces Programming, by Budi Kurniawan (McGraw-Hill/Osborne, ISBN 0-07-222983). If you've enjoyed what you've seen here, click on the "Buy it now!" banner to pick up a copy today!
Buy this book!

>>> More Java & J2EE Articles          >>> More By McGraw-Hill/Osborne

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort


- More Java Bugs Lead to More Attacks
- Oracle's Java One Brings News, Surprises
- Oracle Patches Java Runtime Environment
- Apple Syncs Java Update with Oracle
- Spring 3.1 Java Development Framework Compat...
- Jelastic Java PaaS Availability and Pricing ...
- NetBeans 7.1 Released, Supports JavaFX 2
- SolarWinds Releases Newest Version of Java M...
- Free Monitoring Tool for Java Apps on Heroku
- Heroku Adds JCloud Platform Support, Java 7 ...
- Java SE 8 Speculation in Full Swing
- Java SE 7 Now Available
- New JVM Language and Java Reporting Tool
- Java 7 Release Update and New Eclipse Toolkit
- The Best Java Netbeans IDE Plugins

Developer Shed Affiliates


Dev Shed Tutorial Topics: