Developing a simple JavaServer Faces application usually requires these tasks:
Mapping the FacesServlet instance.
Creating the pages using the UI component and core tags.
Defining page navigation in the application configuration resource file.
Developing the backing beans.
Adding managed bean declarations to the application configuration resource file.
The example used in this section is the guessNumber application, located in the tut-install/javaeetutorial5/examples/web/ directory. It asks you to guess a number between 0 and 10, inclusive. The second page tells you whether you guessed correctly. The example also checks the validity of your input. The system log prints Duke’s number. Figure 10–2 shows what the first page looks like.
The source for the guessNumber application is located in the tut-install/javaeetutorial5/examples/web/guessNumber/ directory created when you unzip the tutorial bundle (see Chapter 2, Using the Tutorial Examples).
To build, package, deploy, and run this example using NetBeans IDE, follow these steps:
In NetBeans IDE, select File->Open Project.
In the Open Project dialog, navigate to:
tut-install/javaeetutorial5/examples/web/ |
Select the guessNumber folder.
Select the Open as Main Project check box.
Click Open Project.
In the Projects tab, right-click the guessNumber project, and select Undeploy and Deploy.
To run the application, open the URL http://localhost:8080/guessNumber in a browser.
To build, package, and deploy this example using Ant, follow these steps:
Go to tut-install/javaeetutorial5/examples/web/guessNumber/.
Type ant.
Start the Application Server.
Type ant deploy.
To run the application, open the URL http://localhost:8080/guessNumber in a browser.
To learn how to configure the example, refer to the deployment descriptor (the web.xml file), which includes the following configurations:
A display-name element that specifies the name that tools use to identify the application.
A servlet element that identifies the FacesServlet instance.
A servlet-mapping element that maps FacesServlet to a URL pattern.