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.web.servlet.ModelAndView;
21 import org.springframework.web.servlet.mvc.Controller;
22 import org.springframework.util.Assert;
23
24 import java.io.IOException;
25
26 import java.util.HashMap;
27 import java.util.List;
28 import java.util.Map;
29
30 import javax.servlet.ServletException;
31 import javax.servlet.http.HttpServletRequest;
32 import javax.servlet.http.HttpServletResponse;
33
34
35 /***
36 * Controller for secure index page.
37 *
38 * @author Ben Alex
39 * @version $Id: SecureIndexController.java,v 1.9 2005/04/15 01:21:32 luke_t Exp $
40 */
41 public class SecureIndexController implements Controller, InitializingBean {
42
43
44 private ContactManager contactManager;
45
46
47
48 public void setContactManager(ContactManager contact) {
49 this.contactManager = contact;
50 }
51
52 public ContactManager getContactManager() {
53 return contactManager;
54 }
55
56 public void afterPropertiesSet() throws Exception {
57 Assert.notNull(contactManager, "A ContactManager implementation is required");
58 }
59
60 public ModelAndView handleRequest(HttpServletRequest request,
61 HttpServletResponse response) throws ServletException, IOException {
62 List myContactsList = contactManager.getAll();
63 Contact[] myContacts;
64
65 if (myContactsList.size() == 0) {
66 myContacts = null;
67 } else {
68 myContacts = (Contact[]) myContactsList.toArray(new Contact[] {});
69 }
70
71 Map model = new HashMap();
72 model.put("contacts", myContacts);
73
74 return new ModelAndView("index", "model", model);
75 }
76 }