diff --git a/spring-framework-reference/src/mvc.xml b/spring-framework-reference/src/mvc.xml index 49e6b4d02f0..1abfdb5ff67 100644 --- a/spring-framework-reference/src/mvc.xml +++ b/spring-framework-reference/src/mvc.xml @@ -676,7 +676,7 @@ public class HelloWorldController { for a specific HTTP method request method ("GET"/"POST") or specific HTTP request parameters. - The following example shows a controller in a JSF application + The following example shows a controller in a Spring MVC application that uses this annotation: @Controller @@ -691,19 +691,13 @@ public class AppointmentsController { } @RequestMapping(method = RequestMethod.GET) - public Appointments get() { + public Map<String, Appointment> get() { return appointmentBook.getAppointmentsForToday(); } @RequestMapping(value="/{day}", method = RequestMethod.GET) - public void getForDay(@PathVariable Date day, ExternalContext context) { - Appointments appts = appointmentBook.getAppointmentsForDay(day); - context.getModel().addAttribute(appts); - context.selectView("appointments"); - if (context.isAjaxRequest()) { - //could activate a ViewHelper for component associated with main - context.renderFragment("main"); - } + public Map<String, Appointment> getForDay(@PathVariable @DateTimeFormat(iso=ISO.DATE) Date day, Model model) { + return appointmentBook.getAppointmentsForDay(day); } @RequestMapping(value="/new", method = RequestMethod.GET) @@ -712,8 +706,11 @@ public class AppointmentsController { } @RequestMapping(method = RequestMethod.POST) - public String post(AppointmentForm form) { - appointmentBook.createAppointment(form); + public String add(@Valid AppointmentForm appointment, BindingResult result) { + if (result.hasErrors()) { + return "appointments/new"; + } + appointmentBook.addAppointment(appointment); return "redirect:/appointments"; } }