1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package sample.contact;
17
18 import org.springframework.web.servlet.ModelAndView;
19 import org.springframework.web.servlet.mvc.SimpleFormController;
20 import org.springframework.web.servlet.view.RedirectView;
21
22 import javax.servlet.ServletException;
23 import javax.servlet.http.HttpServletRequest;
24
25
26 /***
27 * Controller for adding a new contact.
28 *
29 * @author Ben Alex
30 * @version $Id: WebContactAddController.java,v 1.6 2004/11/15 03:25:36 benalex Exp $
31 */
32 public class WebContactAddController extends SimpleFormController {
33
34
35 private ContactManager contactManager;
36
37
38
39 public void setContactManager(ContactManager contactManager) {
40 this.contactManager = contactManager;
41 }
42
43 public ContactManager getContactManager() {
44 return contactManager;
45 }
46
47 public ModelAndView onSubmit(Object command) throws ServletException {
48 String name = ((WebContact) command).getName();
49 String email = ((WebContact) command).getEmail();
50
51 Contact contact = new Contact(name, email);
52 contactManager.create(contact);
53
54 return new ModelAndView(new RedirectView(getSuccessView()));
55 }
56
57 protected Object formBackingObject(HttpServletRequest request)
58 throws ServletException {
59 WebContact wc = new WebContact();
60
61 return wc;
62 }
63 }