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:
22: import org.compass.sample.petclinic.Owner;
23: import org.springframework.web.bind.RequestUtils;
24: import org.springframework.web.servlet.ModelAndView;
25:
26: /**
27: * JavaBean Form controller that is used to edit an existing <code>Owner</code>.
28: *
29: * @author Ken Krebs
30: */
31:
32: public class EditOwnerForm extends AbstractClinicForm {
33:
34: public EditOwnerForm() {
35: // need a session to hold the formBackingObject
36: setSessionForm(true);
37: // initialize the form from the formBackingObject
38: setBindOnNewForm(true);
39: }
40:
41: /** Method forms a copy of an existing Owner for editing */
42: protected Object formBackingObject(HttpServletRequest request)
43: throws ServletException {
44: // get the Owner referred to by id in the request
45: return getClinic().loadOwner(
46: RequestUtils
47: .getRequiredIntParameter(request, "ownerId"));
48: }
49:
50: /** Method updates an existing Owner. */
51: protected ModelAndView onSubmit(Object command)
52: throws ServletException {
53: Owner owner = (Owner) command;
54: // delegate the update to the Business layer
55: getClinic().storeOwner(owner);
56: return new ModelAndView(getSuccessView(), "ownerId", owner
57: .getId());
58: }
59: }
|