Chapter 6 Tutorials

Chapter 6 Tutorials

Complex Form

  1. Use the NetBeans project that was created in the Chapter 1 Tutorials.
  2. Open the Source Packages folder.
    1. Create a new package named ch6.complexForm
      1. Create a new bean name RequestDataComplex for this package.
        1. Add a property for a password.
        2. Add a property for a radio group.
        3. Add a property for a checkbox group.
        4. Add a property for a text area.
        5. Add a property for a single select list.
        6. Add a property for a multiple select list.
      2. Copy the controller class from the Enhanced tutorial for Chapter 4. Refactor as necessary.
      3. Copy the controller helper class from the Enhanced tutorial for Chapter 4. Refactor as necessary.
    2. Modify the controller helper.
      1. Change all bean references to the bean for this package.
      2. Change the location of the JSPs to this package.
    3. Add an edit page to the package.
      1. Add a password field.
      2. Add a radio group.
      3. Add a checkbox group.
      4. Add a text area.
      5. Add a single select list.
      6. Add a multiple select list.
      7. Add a confirm button.
    4. Add a confirm page.
      1. Echo all the data from the query string. Use an ordered list to organize the data.
      2. List all the options for the checkbox group and the multiple select list in nested ordered lists.
      3. Add edit and process buttons.
    5. Add a process page.
      1. Echo all the data from the query string. Use an ordered list to organize the data.
      2. List all the options for the checkbox group and the multiple select list in nested ordered lists.
      3. Add an edit button.
  3. Edit the web.xml file.
    1. Add a servlet definition for the controller.
    2. Add a servlet mapping for the controller.
  4. Modify the index.jsp file.
    1. Modify the page by adding a hypertext link to the controller.
    2. Do not link to the edit page; all accesses should be to the controller.
  5. Run the project.
    1. The index.jsp page will appear in the browser.
    2. Enter data and see that it is displayed properly in the process and confirm pages.
    3. Notice that when you return to the edit page, all the data is lost.
  6. Validate that all the JSP files contain valid HTML.
  7. Whenevere a log file is used. you will need to shut down Tomcat in NetBeans before doing a clean and build.
    1. Click the Services tab in the NetBeans project.
    2. Open the Servers folder.
    3. Right-click Apache Tomcat.
    4. Click Stop.
    5. Now you can do a clean and build.

Complex Initialisation

  1. Open the Source Packages folder.
    1. Add the SetByAttribute class to the shared folder. Copy the contents from the book's site.
    2. Add the AttributeType class to the shared folder. Copy the contents from the book's site.
    3. Add the HelperBaseCh6 class to the shared folder. Copy the contents from the book's site.
      1. This class has member variables for the checked and selected maps.
      2. There are methods for accessing the maps and for adding to the maps.
      3. It contains the method for setting the maps from the query string.
    4. Create a new package named ch6.complexInit.
      1. Copy the bean from the Complex Form tutorial. Rename it RequestDataInit
      2. Copy the controller class from the Post tutorial from Chapter 5. Refactor as necessary.
      3. Copy the controller helper class from the Post tutorial from Chapter 5. Refactor as necessary.
      4. Copy the edit, confirm and process pages from the Complex Form tutorial.
    5. Modify the controller helper.
      1. Extend it from HelperBaseCh6.
      2. Change all bean references to the bean for this package.
      3. Change the location of the JSPs to this package.
      4. In the confirm method, call the setCheckedAndSelected method after filling the bean from the request.
      5. Copy the checked and selected maps from the session in the copyFromSession method.
    6. Modify the bean.
      1. Modify the radio and checkbox properties with the attribute that indicates that they are set using the word "checked".
      2. Modify the select properties with the attribute that indicates that they are set using the word "selected".
    7. Modify the JSPs.
      1. Modify the edit page.
        1. Add initialisation for the password and text area fields.
        2. Add initialisation for the radio and checkbox groups.
        3. Add initialisation for the select lists.
        4. The form should use the POST method.
      2. Modify the confirm and process pages so that the forms use the POST method.
  2. Edit the web.xml file.
    1. Add a servlet definition for the controller.
    2. Add a servlet mapping for the controller.
  3. Modify the index.jsp file.
    1. Modify the page by adding a hypertext link to the controller.
    2. Do not link to the edit page; all accesses should be to the controller.
  4. Run the project.
    1. The index.jsp page will appear in the browser.
    2. Enter data and see that it is displayed properly in the process and confirm pages.
    3. Notice that when you return to the edit page, the elements are all initialised properly.
  5. Validate that all the JSP files contain valid HTML.
  6. Whenevere a log file is used. you will need to shut down Tomcat in NetBeans before doing a clean and build.
    1. Click the Services tab in the NetBeans project.
    2. Open the Servers folder.
    3. Right-click Apache Tomcat.
    4. Click Stop.
    5. Now you can do a clean and build.

Complex Persistence

  1. Open the Source Packages folder.
    1. Create a new package named ch6.complexData.
      1. Copy the controller class and the controller helper class from the Data Persistence tutorial from Chapter 5. Refactor as necessary.
      2. Copy the edit, confirm and process pages from the Complex Init tutorial.
      3. Copy the expired page from the Data Persistence tutorial from Chapter 5
      4. Copy the bean from the Complex Init tutorial. Rename it to ComplexPersistent.
    2. Modify the bean.
      1. Add the class annotation that indicates that the class will have a separate table in the database. Use the one from javax.persistence.
      2. Extend the class from shared.PersistentBase. Alternatively, you can add an id property, but don't do both.
      3. Mark any properties that should not be saved in the database with the appropriate annotation.
      4. Marks the properties that return arrays so that a related table is created in the database.
      5. Add a NotNull annotation for the secret code.
    3. Modify the controller helper.
      1. Change all bean references to the bean for this package.
      2. Change the location of the JSPs to this package.
      3. Add a method named resetNullable that clears the properties for the buttons and lists.
      4. Modify the confirm method so that it calls resetNullable before filling the bean and setCheckedAndSelected after filling the bean.
    4. Modify the process page.
      1. Add the taglib for the JSTL.
      2. Add a forEach loop that displays all the data from the database.
        1. Use EL to retrieve the data using the name that was used to add the data to the request in the process method.
        2. List all the data in a table.
          1. Display a row of headings that contains the name of each property.
          2. Display each row from the database in a separate row in the table
          3. Each column in the table represents one property in the table.
          4. For those properties that have multiple values, display them in an unordered list in the table cell.
      3. Add a form that uses the GET method. Add a button to the form that allows the user to return to the edit page and start a new request.
  2. Edit the web.xml file.
    1. Add a servlet definition for the controller.
      1. Add an initialisation parameter named create.
      2. Set the value to true when you want to create the table; otherwise, leave it as false.
    2. Add a servlet mapping for the controller.
  3. Modify the index.jsp file.
    1. Modify the page by adding a hypertext link to the controller.
    2. Do not link to the edit page; all accesses should be to the controller.
  4. Run the project.
    1. The index.jsp page will appear in the browser.
    2. Enter some data and navigate to the process page.
    3. You will see a list of all the data that you have entered.
    4. Click the Edit button.
    5. Change the values and navigate to the process page.
    6. You will see that the data for the last record was changed, instead of a new record being added.
    7. Click the New button.
    8. Enter some new data and navigate to the process page.
    9. You will see that a new record has been added to the database.
    10. Be sure that the create parameter in the web.xml file is set to false, so that your table will not lose all its data when the servlet engine restarts.
    11. Navigate to the confirm page.
    12. Open another window in the browser and access the manager application. Reload the current web app. Return to the other tab that has the confirm page opened.
    13. You should still be on the confirm page. Click process. You will be redirected to the error page, since the session is no longer accessible and the data is gone.
    14. If there are errors, check your log file for more information.
  5. Validate that all the JSP files contain valid HTML.
  6. Whenevere a log file is used. you will need to shut down Tomcat in NetBeans before doing a clean and build.
    1. Click the Services tab in the NetBeans project.
    2. Open the Servers folder.
    3. Right-click Apache Tomcat.
    4. Click Stop.
    5. Now you can do a clean and build.

Contact the author