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.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      //~ Instance fields ========================================================
    34
    35      private ContactManager contactManager;
    36
    37      //~ Methods ================================================================
    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  }