Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2011
34
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.15 KB | None | 0 0
  1. /**
  2.  * The contents of this file are subject to the OpenMRS Public License
  3.  * Version 1.0 (the "License"); you may not use this file except in
  4.  * compliance with the License. You may obtain a copy of the License at
  5.  * http://license.openmrs.org
  6.  *
  7.  * Software distributed under the License is distributed on an "AS IS"
  8.  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
  9.  * License for the specific language governing rights and limitations
  10.  * under the License.
  11.  *
  12.  * Copyright (C) OpenMRS, LLC.  All Rights Reserved.
  13.  */
  14. package org.openmrs.module.MyFirst.web.controller;
  15.  
  16. import java.util.Collection;
  17.  
  18. import javax.servlet.http.HttpServletRequest;
  19. import javax.servlet.http.HttpSession;
  20.  
  21. import org.apache.commons.logging.Log;
  22. import org.apache.commons.logging.LogFactory;
  23. import org.openmrs.Patient;
  24. import org.openmrs.api.context.Context;
  25. import org.springframework.stereotype.Controller;
  26. import org.springframework.validation.BindingResult;
  27. import org.springframework.web.bind.annotation.ModelAttribute;
  28. import org.springframework.web.bind.annotation.RequestMapping;
  29. import org.springframework.web.bind.annotation.RequestMethod;
  30.  
  31. /**
  32.  * This class configured as controller using annotation and mapped with the URL of 'module/myfirst/myfirstLink.form'.
  33.  */
  34. @Controller
  35. @RequestMapping(value = "module/myfirst/myfirstLink.form")
  36. public class MyFirstFormController{
  37.    
  38.     /** Logger for this class and subclasses */
  39.     protected final Log log = LogFactory.getLog(getClass());
  40.    
  41.     /** Success form view name */
  42.     private final String SUCCESS_FORM_VIEW = "module/myfirst/myfirstForm";
  43.    
  44.     /**
  45.      * Initially called after the formBackingObject method to get the landing form name  
  46.      * @return String form view name
  47.      */
  48.     @RequestMapping(method = RequestMethod.GET)
  49.     public String showForm(){
  50.         return SUCCESS_FORM_VIEW;
  51.     }
  52.    
  53.     /**
  54.      * All the parameters are optional based on the necessity  
  55.      *
  56.      * @param httpSession
  57.      * @param anyRequestObject
  58.      * @param errors
  59.      * @return
  60.      */
  61.     @RequestMapping(method = RequestMethod.POST)
  62.     public String onSubmit(HttpSession httpSession,
  63.                                    @ModelAttribute("anyRequestObject") Object anyRequestObject, BindingResult errors) {
  64.        
  65.         if (errors.hasErrors()) {
  66.             // return error view
  67.         }
  68.        
  69.         return SUCCESS_FORM_VIEW;
  70.     }
  71.    
  72.     /**
  73.      * This class returns the form backing object. This can be a string, a boolean, or a normal java
  74.      * pojo. The bean name defined in the ModelAttribute annotation and the type can be just
  75.      * defined by the return type of this method
  76.      */
  77.     @ModelAttribute("thePatientList")
  78.     protected Collection<Patient> formBackingObject(HttpServletRequest request) throws Exception {
  79.         // get all patients that have an identifier "101" (from the demo sample data)
  80.         // see http://resources.openmrs.org/doc/index.html?org/openmrs/api/PatientService.html for
  81.         // a list of all PatientService methods
  82.         Collection<Patient> patients = Context.getPatientService().findPatients("101", false);
  83.        
  84.         // this object will be made available to the jsp page under the variable name
  85.         // that is defined in the @ModuleAttribute tag
  86.         return patients;
  87.     }
  88.    
  89. }
  90.  
  91.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement