KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > samples > petclinic > web > AddVisitForm


1 package org.springframework.samples.petclinic.web;
2
3 import javax.servlet.ServletException JavaDoc;
4 import javax.servlet.http.HttpServletRequest JavaDoc;
5 import javax.servlet.http.HttpServletResponse JavaDoc;
6
7 import org.springframework.samples.petclinic.Pet;
8 import org.springframework.samples.petclinic.Visit;
9 import org.springframework.web.bind.RequestUtils;
10 import org.springframework.web.servlet.ModelAndView;
11
12 /**
13  * JavaBean form controller that is used to add a new <code>Visit</code> to the system.
14  *
15  * @author Ken Krebs
16  */

17 public class AddVisitForm extends AbstractClinicForm {
18
19     public AddVisitForm() {
20         // need a session to hold the formBackingObject
21
setSessionForm(true);
22     }
23
24     /** Method creates a new <code>Visit</code> with the correct <code>Pet</code> info */
25     protected Object JavaDoc formBackingObject(HttpServletRequest JavaDoc request) throws ServletException JavaDoc {
26         Pet pet = getClinic().loadPet(RequestUtils.getRequiredIntParameter(request, "petId"));
27         Visit visit = new Visit();
28         pet.addVisit(visit);
29         return visit;
30     }
31
32     /** Method inserts a new <code>Visit</code>. */
33     protected ModelAndView onSubmit(Object JavaDoc command) throws ServletException JavaDoc {
34         Visit visit = (Visit) command;
35         // delegate the insert to the Business layer
36
getClinic().storeVisit(visit);
37         return new ModelAndView(getSuccessView(), "ownerId", visit.getPet().getOwner().getId());
38     }
39
40     protected ModelAndView handleInvalidSubmit(HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response)
41             throws Exception JavaDoc {
42         return disallowDuplicateFormSubmission(request, response);
43     }
44
45 }
46
Popular Tags