Chapter 7 Tutorials
Complex Elements
- 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.
- Add a declaration for a prototype bean to the configuration file, SimpleBean.java,
for the new bean.
- Create new views that interact with the new bean.
- In the edit view, use the Spring form tags to automatically fill the fields with data
from the mode.
- In the confirm and process views, use a nested, unordered list from the
JSTL tag library to display
all the data in the bean.
- Copy the controller from the enhanced controller from Chapter 5 to a new class named
ControllerComplexFormSticky
in the controller/ch7/complexForm/sticky/ folder.
- Change the import for the bean to
com.bytesizebook.data.ch7.complexForm .
- Modify the request mapping annotation for the URL pattern
/ch7/complexForm/sticky/collect/ .
- Update all occurrences of the bean interface to the new bean interface.
- Modify the
viewLocation method for the new location of the JSPs.
- 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
- Create folders for data and the controller named
ch7/complexForm/required .
- Create an interface in the data folder and extend it from the previous interface. Add
validation for the multiple-valued getters.
- Implement the interface.
- Add a declaration for a prototype bean to the configuration file, SimpleBean.java,
for the new bean.
- Copy the JSPs from the last application to a new folder named
ch7/complexForm/required .
- Modify the edit page so it displays errors for all the elements that have
validation constraints, including the multiple-valued elements.
- Copy the required validation controller to the folder for this application's controller.
- Change the import for the bean to
com.bytesizebook.data.ch7.complexForm.required .
- Modify the request mapping annotation for the URL pattern
/ch7/complexForm/required/collect/ .
- Update all occurrences of the bean interface to the new bean interface.
- Modify the
viewLocation method for the new location of the JSPs.
Complex Persistence
- Copy the bean from the last example to a new bean named
RequestDataComplexPersistentBean . that
-
Implement the interface from the last example along with Serializable.
- Add the
Entity annotation to the class.
- Annotate the multiple-valued properties with the
ElementCollection
andOrderColumn annotations.
- Add and annotate an id property as was done in the last chapter.
- Define a getter for the new bean in the configuration file.
- Create an interface that extends
WrappedTypeRep with the
new bean for this application.
- Copy the JSPs to a new location,
ch7/complexForm/persistent .
- Add the views from the Chapter 6 persistent controller for records and expired
data.
- Modify the process view so it uses nested, unordered lists to display the data.
- 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.
- Copy the persistent controller from Chapter 6 to a new folder,
ch7/complexForm/persistent .
- Modify the request mapping and autowire the new repo.
- 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.
|