01: /* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
02: *
03: * Licensed under the Apache License, Version 2.0 (the "License");
04: * you may not use this file except in compliance with the License.
05: * You may obtain a copy of the License at
06: *
07: * http://www.apache.org/licenses/LICENSE-2.0
08: *
09: * Unless required by applicable law or agreed to in writing, software
10: * distributed under the License is distributed on an "AS IS" BASIS,
11: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12: * See the License for the specific language governing permissions and
13: * limitations under the License.
14: */
15:
16: package sample.contact;
17:
18: import org.springframework.beans.factory.InitializingBean;
19:
20: import org.springframework.util.Assert;
21:
22: import org.springframework.web.bind.RequestUtils;
23: import org.springframework.web.servlet.ModelAndView;
24: import org.springframework.web.servlet.mvc.Controller;
25:
26: import java.io.IOException;
27:
28: import javax.servlet.ServletException;
29: import javax.servlet.http.HttpServletRequest;
30: import javax.servlet.http.HttpServletResponse;
31:
32: /**
33: * Controller to delete a contact.
34: *
35: * @author Ben Alex
36: * @version $Id: DeleteController.java 1496 2006-05-23 13:38:33Z benalex $
37: */
38: public class DeleteController implements Controller, InitializingBean {
39: //~ Instance fields ================================================================================================
40:
41: private ContactManager contactManager;
42:
43: //~ Methods ========================================================================================================
44:
45: public void afterPropertiesSet() throws Exception {
46: Assert.notNull(contactManager,
47: "A ContactManager implementation is required");
48: }
49:
50: public ContactManager getContactManager() {
51: return contactManager;
52: }
53:
54: public ModelAndView handleRequest(HttpServletRequest request,
55: HttpServletResponse response) throws ServletException,
56: IOException {
57: int id = RequestUtils.getRequiredIntParameter(request,
58: "contactId");
59: Contact contact = contactManager.getById(new Long(id));
60: contactManager.delete(contact);
61:
62: return new ModelAndView("deleted", "contact", contact);
63: }
64:
65: public void setContactManager(ContactManager contact) {
66: this.contactManager = contact;
67: }
68: }
|