Expert Spring MVC and Web Flow

(Dana P.) #1

Building the Search for Flights Use Case


To review, the second use case allows the user to search for a flight by departure location and
time, arrival location, and return time. We have already built the business logic and service
layer for this use case, using the class SearchFlightsand the service method findFlights().
To implement this feature, we will now implement the XHTML form and the form handling


SimpleFormController


Form handling in Spring MVC works similar to Struts, in that it will create a bean on form
submission and populate it with the fields from the form. This bean is then provided to a
Controllerfor processing.
Unlike Struts, Spring MVC is able to populate any JavaBean, no matter what class or
interface the bean implements. In other words, Spring MVC does not mandate a particular
superclass like Struts does with its FormBeanclass. For this reason, form handling in Spring
MVC is very flexible, able to populate both simple JavaBeans as well as complex, deeply nested
beans. It is even common to use the domain object model for the form beans, in order to min-
imize the number of classes required in the system.


SimpleFormController


When handling forms in Spring MVC, the SimpleFormControlleris the class you will most
often extend. This Controllerimplements a well-defined form handling life cycle, and it
provides many points for extension, making it extremely customizable.
Figure 4-5 illustrates a simplified default version of the form submission work flow for
SimpleFormController. Keep in mind that much of this work flow is configurable based on your
needs. A much more detailed version of this work flow diagram can be found in Chapter 6.


Figure 4-5.Basic form submission work flow for SimpleFormController


Validate command bean

Create command bean

Show initial form page

Show success page

Process form

Form submit

No

No

Yes

Has errors?

Yes

Requires validation?

CHAPTER 4 ■JUMP INTO SPRING MVC 65
Free download pdf