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.Owner;
24: import org.springframework.web.servlet.ModelAndView;
25:
26: /**
27: * JavaBean form controller that is used to add a new <code>Owner</code> to
28: * the system.
29: *
30: * @author Ken Krebs
31: */
32: public class AddOwnerForm extends AbstractClinicForm {
33:
34: public AddOwnerForm() {
35: // OK to start with a blank command object
36: setCommandClass(Owner.class);
37: // activate session form mode to allow for detection of duplicate
38: // submissions
39: setSessionForm(true);
40: }
41:
42: /** Method inserts a new <code>Owner</code>. */
43: protected ModelAndView onSubmit(Object command)
44: throws ServletException {
45: Owner owner = (Owner) command;
46: // delegate the insert to the Business layer
47: getClinic().storeOwner(owner);
48: return new ModelAndView(getSuccessView(), "ownerId", owner
49: .getId());
50: }
51:
52: protected ModelAndView handleInvalidSubmit(
53: HttpServletRequest request, HttpServletResponse response)
54: throws Exception {
55: return disallowDuplicateFormSubmission(request, response);
56: }
57: }
|