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.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: * Controller for adding a new contact.
27: *
28: * @author Ben Alex
29: * @version $Id: WebContactAddController.java 1496 2006-05-23 13:38:33Z benalex $
30: */
31: public class WebContactAddController extends SimpleFormController {
32: //~ Instance fields ================================================================================================
33:
34: private ContactManager contactManager;
35:
36: //~ Methods ========================================================================================================
37:
38: protected Object formBackingObject(HttpServletRequest request)
39: throws ServletException {
40: WebContact wc = new WebContact();
41:
42: return wc;
43: }
44:
45: public ContactManager getContactManager() {
46: return contactManager;
47: }
48:
49: public ModelAndView onSubmit(Object command)
50: throws ServletException {
51: String name = ((WebContact) command).getName();
52: String email = ((WebContact) command).getEmail();
53:
54: Contact contact = new Contact(name, email);
55: contactManager.create(contact);
56:
57: return new ModelAndView(new RedirectView(getSuccessView()));
58: }
59:
60: public void setContactManager(ContactManager contactManager) {
61: this.contactManager = contactManager;
62: }
63: }
|