Skip to content

Commit

Permalink
TRUNK-3956 ~ caught the DataIntegrityViolationException error
Browse files Browse the repository at this point in the history
  • Loading branch information
k-joseph committed Jul 18, 2013
1 parent ea4e844 commit 996ddca
Showing 1 changed file with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import org.openmrs.web.WebConstants;
import org.springframework.beans.propertyeditors.CustomNumberEditor;
import org.springframework.context.support.MessageSourceAccessor;
import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.validation.BindException;
import org.springframework.validation.Errors;
import org.springframework.web.bind.ServletRequestDataBinder;
Expand Down Expand Up @@ -70,7 +71,7 @@ protected void initBinder(HttpServletRequest request, ServletRequestDataBinder b
*/
@Override
protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object obj,
BindException errors) throws Exception {
BindException errors) throws Exception {

HttpSession httpSession = request.getSession();
String view = getFormView();
Expand Down Expand Up @@ -99,6 +100,10 @@ protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse
Context.getFormService().purgeForm(form);
httpSession.setAttribute(WebConstants.OPENMRS_MSG_ATTR, "Form.deleted");
}
catch (DataIntegrityViolationException e) {
httpSession.setAttribute(WebConstants.OPENMRS_ERROR_ATTR, "Form.cannot.delete");
return new ModelAndView(new RedirectView("formEdit.form?formId=" + form.getFormId()));
}
catch (Exception e) {
log.error("Error while deleting form " + form.getFormId(), e);
errors.reject(e.getMessage());
Expand Down

0 comments on commit 996ddca

Please sign in to comment.