Chapter 7 Tutorials

Complex Elements

  1. Create a new interface that extends the interface for required data and a bean for the new form elements in the data/ch7/complexForm/sticky. Add a password field, a radio button group, a checkbox group, a text area, a drop-down list and a multiple-selection list to the new interface.
  2. Add a declaration for a prototype bean to the configuration file, SimpleBean.java, for the new bean.
  3. Create new views that interact with the new bean.
    1. In the edit view, use the Spring form tags to automatically fill the fields with data from the mode.
    2. In the confirm and process views, use a nested, unordered list from the JSTL tag library to display all the data in the bean.
  4. Copy the controller from the enhanced controller from Chapter 5 to a new class named ControllerComplexFormSticky in the controller/ch7/complexForm/sticky/ folder.
  5. Change the import for the bean to com.bytesizebook.data.ch7.complexForm.
  6. Modify the request mapping annotation for the URL pattern /ch7/complexForm/sticky/collect/.
  7. Update all occurrences of the bean interface to the new bean interface.
  8. Modify the viewLocation method for the new location of the JSPs.
  9. Run the application, add data in the edit view, review the data in the confirm view, then return to the edit view. All the data is there, except the password field.

Complex Validation

  1. Create folders for data and the controller named ch7/complexForm/required.
  2. Create an interface in the data folder and extend it from the previous interface. Add validation for the multiple-valued getters.
  3. Implement the interface.
  4. Add a declaration for a prototype bean to the configuration file, SimpleBean.java, for the new bean.
  5. Copy the JSPs from the last application to a new folder named ch7/complexForm/required.
  6. Modify the edit page so it displays errors for all the elements that have validation constraints, including the multiple-valued elements.
  7. Copy the required validation controller to the folder for this application's controller.
  8. Change the import for the bean to com.bytesizebook.data.ch7.complexForm.required.
  9. Modify the request mapping annotation for the URL pattern /ch7/complexForm/required/collect/.
  10. Update all occurrences of the bean interface to the new bean interface.
  11. Modify the viewLocation method for the new location of the JSPs.

Complex Persistence

  1. Copy the bean from the last example to a new bean named RequestDataComplexPersistentBean. that
  2. Implement the interface from the last example along with Serializable.
  3. Add the Entity annotation to the class.
  4. Annotate the multiple-valued properties with the ElementCollection andOrderColumn annotations.
  5. Add and annotate an id property as was done in the last chapter.
  6. Define a getter for the new bean in the configuration file.
  7. Create an interface that extends WrappedTypeRep with the new bean for this application.
  8. Copy the JSPs to a new location, ch7/complexForm/persistent.
  9. Add the views from the Chapter 6 persistent controller for records and expired data.
  10. Modify the process view so it uses nested, unordered lists to display the data.
  11. Modify the viewAll page so it uses a table to display all the records from the database. Use an unordered list to display the values in a multiple-valued el ement.
  12. Copy the persistent controller from Chapter 6 to a new folder, ch7/complexForm/persistent.
  13. Modify the request mapping and autowire the new repo.
  14. Until now, each example that created a new interface used the new interface in the controller. In reality, the controller could still have referenced the original RequestData interface, since no details of the bean are every used in the controller. This example uses the original RequestData interface in the controller, even though the new interface is used behind the scenes.

Contact the author