@@ -676,7 +676,7 @@ public class HelloWorldController {
676
676
for a specific HTTP method request method ("GET"/"POST") or specific
677
677
HTTP request parameters.</para >
678
678
679
- <para >The following example shows a controller in a JSF application
679
+ <para >The following example shows a controller in a Spring MVC application
680
680
that uses this annotation:</para >
681
681
682
682
<programlisting language =" java" >@Controller
@@ -691,19 +691,13 @@ public class AppointmentsController {
691
691
}
692
692
693
693
<emphasis role =" bold" >@RequestMapping(method = RequestMethod.GET)</emphasis >
694
- public Appointments get() {
694
+ public Map < String, Appointment > get() {
695
695
return appointmentBook.getAppointmentsForToday();
696
696
}
697
697
698
698
<emphasis role =" bold" >@RequestMapping(value="/{day}", method = RequestMethod.GET)</emphasis >
699
- public void getForDay(@PathVariable Date day, ExternalContext context) {
700
- Appointments appts = appointmentBook.getAppointmentsForDay(day);
701
- context.getModel().addAttribute(appts);
702
- context.selectView("appointments");
703
- if (context.isAjaxRequest()) {
704
- //could activate a ViewHelper for component associated with main
705
- context.renderFragment("main");
706
- }
699
+ public Map< String, Appointment> getForDay(@PathVariable @DateTimeFormat(iso=ISO.DATE) Date day, Model model) {
700
+ return appointmentBook.getAppointmentsForDay(day);
707
701
}
708
702
709
703
<emphasis role =" bold" >@RequestMapping(value="/new", method = RequestMethod.GET)</emphasis >
@@ -712,8 +706,11 @@ public class AppointmentsController {
712
706
}
713
707
714
708
<emphasis role =" bold" >@RequestMapping(method = RequestMethod.POST)</emphasis >
715
- public String post(AppointmentForm form) {
716
- appointmentBook.createAppointment(form);
709
+ public String add(@Valid AppointmentForm appointment, BindingResult result) {
710
+ if (result.hasErrors()) {
711
+ return "appointments/new";
712
+ }
713
+ appointmentBook.addAppointment(appointment);
717
714
return "redirect:/appointments";
718
715
}
719
716
}</programlisting >
0 commit comments