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

Wrtiting the JSP Files for the Page Navigation Example - Java

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).

TABLE OF CONTENTS:
  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
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

This application has two JSP pages (page1.jsp and page2.jsp) as the user interface. The page1.jsp page is shown in Listing 8, and the page2.jsp page is shown in Listing 9.

Listing 8 The page1.jsp File


<f:use_faces><?xml:namespace prefix /><h:form formName="surveyForm"><%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<html>
<head>
<title>Online Survey</title>
</head>
<body>
<h2>Online Survey</h2>
<f:use_faces>
<h:form formName="surveyForm" >
  
<br/>Favorite Singer:
  
<h:input_text id="favSinger" valueRef="surveyBean.favSinger"/>
  
<br/>Favorite Band:
  
<h:input_text id="favBand" valueRef="surveyBean.favBand"/>
  
<br/>
  
<h:command_button id="submit" label="Submit"
  commandName
="submit" />
</h:form>
</f:use_faces>
</body>
</html>



Listing 9 The page2.jsp File


<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<html>
<head>
<title>Thank You</title>
</head>
<body>
<h2>Thank you for your feedback.</h2>
<f:use_faces>
<h:form formName="thankYouForm" >
Your favorite singer is
<h:output_text id="favSinger" valueRef="surveyBean.favSinger"/>
and your favorite band is
<h:output_text id="favBand" valueRef="surveyBean.favBand"/>
<br/>Nowclick the button to go back to the previous page.
<br/>
<h:command_button id="goBack" label="Go Back"
commandName
="goBack" />
</h:form>
</f:use_faces>
</body>
</html>

In both pages, you use the same UI components you used in the previous examples. In the page1.jsp file, you use a form containing two UIInput components for the users favorite singer and favorite band. Both UIInput components are bound to the SurveyBeans properties.

In the page2.jsp page, you use two UIOutput components to display the values entered by the user. The UIOutput components are also bound to the SurveyBeans properties, from which the components get their values. <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>

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
   

JAVA & J2EE ARTICLES

- 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: