1
2
3
4
5
6
7
8
9
10
11
12
13
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 /***
34 * Controller to delete a contact.
35 *
36 * @author Ben Alex
37 * @version $Id: DeleteController.java,v 1.5 2005/11/04 04:15:57 benalex Exp $
38 */
39 public class DeleteController implements Controller, InitializingBean {
40
41
42 private ContactManager contactManager;
43
44
45
46 public void setContactManager(ContactManager contact) {
47 this.contactManager = contact;
48 }
49
50 public ContactManager getContactManager() {
51 return contactManager;
52 }
53
54 public void afterPropertiesSet() throws Exception {
55 Assert.notNull(contactManager,
56 "A ContactManager implementation is required");
57 }
58
59 public ModelAndView handleRequest(HttpServletRequest request,
60 HttpServletResponse response) throws ServletException, IOException {
61 int id = RequestUtils.getRequiredIntParameter(request, "contactId");
62 Contact contact = contactManager.getById(new Long(id));
63 contactManager.delete(contact);
64
65 return new ModelAndView("deleted", "contact", contact);
66 }
67 }