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.servlet.ModelAndView;
23: import org.springframework.web.servlet.mvc.Controller;
24:
25: import java.io.IOException;
26:
27: import javax.servlet.ServletException;
28: import javax.servlet.http.HttpServletRequest;
29: import javax.servlet.http.HttpServletResponse;
30:
31: /**
32: * Controller for public index page (default web app home page).
33: *
34: * @author Ben Alex
35: * @version $Id: PublicIndexController.java 1496 2006-05-23 13:38:33Z benalex $
36: */
37: public class PublicIndexController implements Controller,
38: 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: Contact rnd = contactManager.getRandomContact();
58:
59: return new ModelAndView("hello", "contact", rnd);
60: }
61:
62: public void setContactManager(ContactManager contact) {
63: this.contactManager = contact;
64: }
65: }
|