Expert Spring MVC and Web Flow

(Dana P.) #1
setCommandClass(CreateAccount.class);
setValidator(new CreateAccountValidator());
setPages(new String[]{"usernameAndEmail", "billingAddress"});
}

public void setAccountService(AccountService accountService) {
this.accountService = accountService;
}

@Override
protected void validatePage(Object command, Errors errors, int page) {
CreateAccount createAccount = (CreateAccount) command;
CreateAccountValidator validator = (CreateAccountValidator) getValidator();
switch (page) {
case 0:
validator.validatePage0(createAccount, errors);
break;
case 1:
validator.validatePage1(createAccount, errors);
break;
}
}

@Override
protected ModelAndView processFinish(HttpServletRequest request,
HttpServletResponse response, Object command, BindException errors)
throws Exception {
CreateAccount createAccount = (CreateAccount) command;
accountService.saveAccount(createAccount.getAccount());
return new ModelAndView("createAccountSuccess",
"account", createAccount.getAccount());
}

}

This controller looks a lot like a SimpleFormController, with the exception of the
validatePage()method.

Summary
The AbstractWizardFormControllerprovides a multistep wizard work flow, appropriate for
splitting large forms across many pages. This wizard works with a single command object,
populating it as the user moves through the pages.
The wizard supports three different types of state changes: page change, cancellation, and
completion. By default, each state change is triggered by the existence of well-known request
parameters, but this behavior is easily overridden with the appropriate methods.

192 CHAPTER 6 ■THE CONTROLLER MENAGERIE

Free download pdf