throws Exception {
if (log.isDebugEnabled()) {
log.debug("entering 'onSubmit' method...");
}
DefectCategory defectCategory = (DefectCategory) command;
boolean isNew = (defectCategory.getDefectCategoryId() == null);
Locale locale = request.getLocale();
if (request.getParameter("delete") != null) {
defectCategoryManager.removeDefectCategory(defectCategory.getDefectCategoryId().toString());
saveMessage(request, getText("defectCategory.deleted", locale));
} else {
Integer varityId = defectCategory.getDefectVarity().getVarityId();
if (varityId.equals(new Integer(-1))) {
defectCategory.setDefectVarity(null);
} else {
defectCategory.setDefectVarity(defectVarityManager.getDefectVarity(varityId.toString()));
}
Integer defectZoneId = defectCategory.getDefectZone().getDefectZoneId();
if (!defectZoneId.equals(new Integer(-1))) {
defectCategory.setDefectZone(defectZoneManager.getDefectZone(defectZoneId.toString()));
}
Integer constructionTypeId = defectCategory.getConstructionType().getConstructionTypeId();
if (!constructionTypeId.equals(new Integer(-1))) {
defectCategory.setConstructionType(constructionTypeManager.getConstructionType(constructionTypeId.toString()));
}
Integer defectCategoryNameId = defectCategory.getDefectCategoryName().getDefectCategoryNameId();
if (!defectCategoryNameId.equals(new Integer(-1))) {
defectCategory.setDefectCategoryName(defectCategoryNameManager.getDefectCategoryName(defectCategoryNameId.toString()));
}
List categoryParameters = new ArrayList();
List categoryParametersFromForm = defectCategory.getCategoryParameters();
for (int i = 0; i < categoryParametersFromForm.size(); i++) {
CategoryParameter categoryParameter = (CategoryParameter) categoryParametersFromForm.get(i);
categoryParameter.setParameter(parameterManager.getParameter(categoryParameter.getParameter().getParameterId().toString()));
categoryParameters.add(categoryParameter);
}
defectCategory.setCategoryParameters(categoryParameters);
defectCategoryManager.saveDefectCategory(defectCategory);
String key = (isNew) ? "defectCategory.added" : "defectCategory.updated";
saveMessage(request, getText(key, locale));
if (defectCategory.isEdited()) {
return new ModelAndView("redirect:updating.html?id=" + defectCategory.getDefectCategoryId() + "&fieldId=" + request.getParameter("fieldId"));
}
}
return new ModelAndView("redirect:" + defectCategory.getDocLocation());
}