throws Exception {
if (log.isDebugEnabled()) {
log.debug("entering 'onSubmit' method...");
}
Reason reason = (Reason) command;
boolean isNew = (reason.getReasonId() == null);
Locale locale = request.getLocale();
if (request.getParameter("delete") != null) {
reasonManager.removeReason(reason.getReasonId().toString());
saveMessage(request, getText("reason.deleted", locale));
} else {
// List reasonDefects = new ArrayList();
// List reasonDefectsFromForm = reason.getDefects();
// for (int i = 0; i < reasonDefectsFromForm.size(); i++) {
// DefectType defectType = (DefectType) reasonDefectsFromForm.get(i);
//
//
// reasonDefects.add(defectTypeManager.getDefectType(defectType.getDefectTypeId().toString()));
// }
//
// reason.setDefects(reasonDefects);
Integer constructionTypeId = reason.getConstructionType().getConstructionTypeId();
if (!constructionTypeId.equals(new Integer(-1))) {
reason.setConstructionType(constructionTypeManager.getConstructionType(constructionTypeId.toString()));
}
Integer defectZoneId = reason.getDefectZone().getDefectZoneId();
if (!defectZoneId.equals(new Integer(-1))) {
reason.setDefectZone(defectZoneManager.getDefectZone(defectZoneId.toString()));
}
Integer defectTypeId = reason.getDefectType().getDefectTypeId();
if (!defectTypeId.equals(new Integer(-1))) {
reason.setDefectType(defectTypeManager.getDefectType(defectTypeId.toString()));
}
Integer defectVarityId = reason.getDefectVarity().getVarityId();
if (!defectVarityId.equals(new Integer(-1))) {
reason.setDefectVarity(defectVarityManager.getDefectVarity(defectVarityId.toString()));
}
Integer reasonNameId = reason.getReasonName().getReasonNameId();
if (!reasonNameId.equals(new Integer(-1))) {
reason.setReasonName(reasonNameManager.getReasonName(reasonNameId.toString()));
}
reasonManager.saveReason(reason);
String key = (isNew) ? "reason.added" : "reason.updated";
saveMessage(request, getText(key, locale));
if (reason.isEdited()) {
return new ModelAndView("redirect:updating.html?id=" + reason.getReasonId() + "&fieldId=" + request.getParameter("fieldId"));
}
}
return new ModelAndView("redirect:" + reason.getDocLocation());
}