/** * The onSubmit function receives the form/command object that was modified by the input form and * saves it to the db * * @see * org.springframework.web.servlet.mvc.SimpleFormController#onSubmit(javax.servlet.http.HttpServletRequest, * javax.servlet.http.HttpServletResponse, java.lang.Object, * org.springframework.validation.BindException) */ protected ModelAndView onSubmit( HttpServletRequest request, HttpServletResponse response, Object obj, BindException errors) throws Exception { HttpSession httpSession = request.getSession(); String view = getFormView(); if (Context.isAuthenticated()) { Drug drug = (Drug) obj; ConceptService conceptService = Context.getConceptService(); if (request.getParameter("retireDrug") != null) { String retireReason = request.getParameter("retireReason"); if (drug.getId() != null && (retireReason == null || retireReason.length() == 0)) { errors.reject("retireReason", "ConceptDrug.retire.reason.empty"); return showForm(request, response, errors); } conceptService.retireDrug(drug, retireReason); httpSession.setAttribute(WebConstants.OPENMRS_MSG_ATTR, "ConceptDrug.retiredSuccessfully"); } // if this obs is already voided and needs to be unvoided else if (request.getParameter("unretireDrug") != null) { conceptService.unretireDrug(drug); httpSession.setAttribute( WebConstants.OPENMRS_MSG_ATTR, "ConceptDrug.unretiredSuccessfully"); } else { conceptService.saveDrug(drug); httpSession.setAttribute(WebConstants.OPENMRS_MSG_ATTR, "ConceptDrug.saved"); } view = getSuccessView(); } return new ModelAndView(new RedirectView(view)); }