01: /*
02: * Copyright 2004-2006 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16:
17: package org.compass.sample.petclinic.web;
18:
19: import javax.servlet.ServletException;
20: import javax.servlet.http.HttpServletRequest;
21: import javax.servlet.http.HttpServletResponse;
22:
23: import org.compass.sample.petclinic.Pet;
24: import org.compass.sample.petclinic.Visit;
25: import org.springframework.web.bind.RequestUtils;
26: import org.springframework.web.servlet.ModelAndView;
27:
28: /**
29: * JavaBean form controller that is used to add a new <code>Visit</code> to
30: * the system.
31: *
32: * @author Ken Krebs
33: */
34:
35: public class AddVisitForm extends AbstractClinicForm {
36:
37: public AddVisitForm() {
38: // need a session to hold the formBackingObject
39: setSessionForm(true);
40: }
41:
42: /**
43: * Method creates a new <code>Visit</code> with the correct
44: * <code>Pet</code> info
45: */
46: protected Object formBackingObject(HttpServletRequest request)
47: throws ServletException {
48: Pet pet = getClinic().loadPet(
49: RequestUtils.getRequiredIntParameter(request, "petId"));
50: Visit visit = new Visit();
51: pet.addVisit(visit);
52: return visit;
53: }
54:
55: /** Method inserts a new <code>Visit</code>. */
56:
57: protected ModelAndView onSubmit(Object command)
58: throws ServletException {
59: Visit visit = (Visit) command;
60: // delegate the insert to the Business layer
61: getClinic().storeVisit(visit);
62: return new ModelAndView(getSuccessView(), "ownerId", visit
63: .getPet().getOwner().getId());
64: }
65:
66: protected ModelAndView handleInvalidSubmit(
67: HttpServletRequest request, HttpServletResponse response)
68: throws Exception {
69: return disallowDuplicateFormSubmission(request, response);
70: }
71: }
|