Big Java Lab 27

Warming Up

1.

Create a JSF page that uses a bean to display a random number between 1000 and 9999. Use the following format:

Today's lucky number is 1729.

What is the code of your bean class?


2.

What are the contents of your index.jsp file? Note: your file can have a different name.


3.

What are the contents of your web.xml file?


4.

What are the contents of your faces-config.xml file?


5.

Describe the directory structure of your application.

A Simple JSF Program


6.

Create a JSP page that uses a JavaBean to display a random "fortune."

Create a list of ten fortunes. When a user opens the page, display a random fortune.

Sample output:
__________________________________________________

The Virtual Fortune Cookie
Your fortune: A short stranger will soon enter your life.
__________________________________________________

What is the code of your bean class(es)?


7.

What are the contents of your *.jsp file(s)?

Interacting with the User

8.

Create a JSF page that allows a user to enter a category for the fortune that they want to have displayed. Categories might include

  • Love
  • Money
  • Food
  • Computers
The program displays a fortune that matches the category that the user selected.
Sample output:
__________________________________________________

The Virtual Fortune Cookie
Your fortune: That wasn't chicken you just ate.
__________________________________________________

What is the code of your bean class(es)?

Error Checking and Navigation

10.

Create a JSF page that allows a user to enter a category for the fortune that they want to have displayed. Use a text field for the category.

If the user entered an unknown category, show an appropriate message. If the user entered a known category, show a fortune cookie. Both pages should have a "Back" button that returns to the original page.

What is the code of your bean class(es)?


11.

What are the contents of your *.jsp file(s)?


12.

In what file did you include your navigation rules? How did you define them?

Database Connectivity

13.

For a more robust program, we want to store the fortunes and their categories in a database.

Modify the bean code so that it looks up fortunes in a database table.

What is the code of your bean class(es)? (You should not modify the JSF pages.)


14.

Give a SQL script that populates the database table. 


15.

What error message do you get when a user connects to your JSF application when the database server is not running?