Figure 6-3.Initial form view
The XHTML shown in Listing 6-41 has some interesting aspects. First, notice that we are
using the POST method for the form. This should be the preferred method for form submis-
sions, as discussed earlier. Second, notice how we used action=""instead of specifying a
particular URI. This is a convenience trick to avoid specifying the page’s URI, which would
tightly couple the page to the URI that indicates it. By not specifying an action, the browser
will submit the form back to the originating URI (which, in the case of SimpleFormController,
is just what we want). Lastly, notice how the form input element names correspond to the
property names from the Personobject. This should be familiar from the discussion about
the DataBinder.
Next, we show the SimpleFormControllerimplementation (Listing 6-42) for the form in
Listing 6-41. For our example, it will simply print out the Personvia toString(), but it’s easy to
imagine using a data access object to persist the person.
Listing 6-42.PersonFormController
public class PersonFormController extends SimpleFormController {
public PersonFormController() {
setCommandName("person");
setCommandClass(Person.class);
setFormView("newPerson");
setSuccessView("newPersonSuccess");
}
@Override
protected void initBinder(HttpServletRequest request,
ServletRequestDataBinder binder) throws Exception {
binder.registerCustomEditor(Date.class,
new CustomDateEditor(new SimpleDateFormat("yyyy-MM-dd"), false));
}
@Override
158 CHAPTER 6 ■THE CONTROLLER MENAGERIE