View Javadoc

    1   /* Copyright 2004 Acegi Technology Pty Limited
    2    *
    3    * Licensed under the Apache License, Version 2.0 (the "License");
    4    * you may not use this file except in compliance with the License.
    5    * You may obtain a copy of the License at
    6    *
    7    *     http://www.apache.org/licenses/LICENSE-2.0
    8    *
    9    * 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.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 javax.servlet.ServletException;
    27  import javax.servlet.http.HttpServletRequest;
    28  import javax.servlet.http.HttpServletResponse;
    29
    30
    31  /***
    32   * Controller for public index page (default web app home page).
    33   *
    34   * @author Ben Alex
    35   * @version $Id: PublicIndexController.java,v 1.3 2005/04/15 01:21:32 luke_t Exp $
    36   */
    37  public class PublicIndexController implements Controller, InitializingBean {
    38      //~ Instance fields ========================================================
    39
    40      private ContactManager contactManager;
    41
    42      //~ Methods ================================================================
    43
    44      public void setContactManager(ContactManager contact) {
    45          this.contactManager = contact;
    46      }
    47
    48      public ContactManager getContactManager() {
    49          return contactManager;
    50      }
    51
    52      public void afterPropertiesSet() throws Exception {
    53          Assert.notNull(contactManager, "A ContactManager implementation is required");
    54      }
    55
    56      public ModelAndView handleRequest(HttpServletRequest request,
    57          HttpServletResponse response) throws ServletException, IOException {
    58          Contact rnd = contactManager.getRandomContact();
    59
    60          return new ModelAndView("hello", "contact", rnd);
    61      }
    62  }