Introduction to JavaServer Faces, Part 3 - Wrtiting the JSP Files for the Page Navigation Example
(Page 2 of 7 )
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 /><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/>Now, click 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 user’s favorite singer and favorite band. Both UIInput components are bound to the SurveyBean‘s 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 SurveyBean‘s properties, from which the components get their values. <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
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! |
Next: Creating the Application Configuration File for the Page Navigation Example >>
More Java Articles
More By McGraw-Hill/Osborne