JSF Exercises

  1. Implement the following navigation flow. You start at a.jsf, press a button, and randomly get either b.jsf or defeat.jsf. From page b, after pressing a button you randomly get c.jsf or defeat.jsf. From page c, after pressing a button you randomly get victory.jsf or defeat.jsf. Note that since JSF navigation is based on forwarding, not redirects, when you press a button, the URL of the previous page is shown in the browser.
  2. Make a page that collects a first name and a last name. If either the first or last name is missing (i.e., an empty string), show an error page. If both the names are there, go to a results page that shows the first and last names in a bulleted (<ul>) list.
  1. Make a form to gather an employee name, employee ID, and the name of a health plan to sign up for. If all three values are present (i.e., are something other than empty strings), display a confirmation page that says “You are registered for the health plan” and that shows the name, ID, and health plan. If any of the inputs are missing, display a page that says “Missing Input Data”.
  2. Make a new form that works similarly to the old one. This time, however, verify that the health plan entered is really one of the available health plans. Give an error message (e.g., “CMS Prime is not an available health plan”) for unknown health plans. In the confirmation page, also show the monthly premium and contact phone number for that health plan (in addition to the data shown earlier). This requirement means that you need some simple business logic to map a health plan name to a HealthPlan object.
  3. Copy your code for the health plan from the previous set of exercises. However, instead of using a textfield for the health care provider, provide a drop down menu that shows a list of the available options.
  1. Make an app where you select one of three names (Cay, David, Marty) and show the selection in the results page. Use a listbox or set of radio buttons, not a dropdown menu. Be sure there is an initial selection.
  2. Make a similar app, but with two differences • Use a dropdown menu • Select among Cay, David, and Marty, but for the results, show one of Cay Horstmann, David Geary, or Marty Hall.
  1. Make a new project. Give it a form where people send their employee details in order to register for some corporate service. Your bean should have the following properties: first name, middle name, last name, employee ID, and building number. Make all of them be strings except for building number, which can be an int. Enforce that all fields except middle name are required. Put the error messages at the top.
  2. Copy the form from the previous problem, but this time display the error message next to the field that had the incorrect value. The trickiest part about this is handling the fact that you have a 3-column table, but have no potential error message for the middle name, since it is optional. One way to handle this is to use h:outputText with an empty string as a value.
  3. Copy the form from the previous problem, but this time enforce stricter rules: • First name: at least two letters • Middle name: optional • Last name: at least three letters • Employee ID: a lowercase letter followed by four numbers. If you know regular expressions in Java, enforce the whole pattern. If you don’t, just enforce that it is exactly five characters long. • Building number: whole number from 1 to 50
  1. Define a TestScores class that represents grades on four exams. For example, TestScores might have getExam1, getExam2, getExam3, and getExam4 methods, each of which returns a number. For instance, a single TestScores object might represent the exam scores for a single person in a semester, and an array of TestScores objects might represent the exam scores for several students. Make a bean that contains an array of TestScores, and display the values in a table. Each row of the table should represent the four exams for an individual TestScores object.
  2. Add headings. For the headings, use large red text with a yellow background. For the rows, use the following: make the first row be black on white, the second row be black on gray, the third row be white on black, and repeat for all subsequent rows.