Expert Spring MVC and Web Flow

(Dana P.) #1

Listing 6-45 contains the entire PersonFormControllercode, highlighting the
referenceData()method.


Listing 6-45.PersonFormController with Reference Data


public class PersonFormController extends SimpleFormController {


private String[] languages = new String[]{"Java", "Ruby", "Python"};

public PersonFormController() {
setCommandName("person");
setCommandClass(Person.class);
setFormView("newPerson");
setSuccessView("newPersonSuccess");
}

@Override
protected Map referenceData(HttpServletRequest req) throws Exception {
Map data = new HashMap();
data.put("languages", languages);
return data;
}

@Override
protected void initBinder(HttpServletRequest request,
ServletRequestDataBinder binder) throws Exception {
binder.registerCustomEditor(Date.class,
new CustomDateEditor(new SimpleDateFormat("yyyy-MM-dd"), false));
}

@Override
protected void doSubmitAction(Object command) throws Exception {
Person person = (Person) command;
}

}


Now that we are providing a list of favorite languages, we can modify our form XHTML to
loop through them to build the

CHAPTER 6 ■THE CONTROLLER MENAGERIE 161
Free download pdf