We continue with part two of Chapter 2 of Introduction JavaServer Faces Programming, by Budi Kurniawan (McGraw-Hill/Osborne, ISBN 0-07-222983-7, 2004). This section deals with the ActionListener and Component Tree, as well as validation and navigation for your JSP pages. This chapter prepares you for the next chapters by introducing the JSF Application Programming Interface (API) and the Application Configuration file.
More informative is the message that is displayed in the console:
getFirstNumber: 0 getSecondNumber: 0 processAction called The id of the component that fired the action event: submitButton Action command: submit ----------- Component Tree ------------- null addForm firstNumber secondNumber output submitButton ---------------------------------------- setFirstNumber: 10 setSecondNumber: 20 getFirstNumber: 10 getSecondNumber: 20 getResult: 30
Creating the Validator Example
The example presented in this section demonstrates how you can validate user input very easily in JSF. This application is even simpler than the one presented in the previous section. It consists of only one JSP page, and it does not require a JavaBean or an application configuration file. However, you will still need a directory structure for the application and the deployment descriptor. The deployment descriptor is the same as the one in Listing 1. Here, we will look at the directory structure and JSP page.
Creating the Directory Structure for the Validator Example
The directory structure for your application, called JSFCh02b, is depicted in Figure 8. In Tomcat, you create this under webapps. The directory contains all the required components that you will build in this example.
Again, you must copy the .jar files containing the JSF implementation into the WEB-INF/lib directory. Then, in the application directory, you have the validatorTest.jsp page.
Remember: This is part one of the second chapter of JavaServer Faces Programming, by Budi Kurniawan (McGraw-Hill/Osborne, ISBN 0-07-222983). Stay tuned for more helpful chapters from McGraw-Hill/Osborne. Buy this book!