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).
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.
<%@ 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!