throws Exception {
if (log.isDebugEnabled()) {
log.debug("entering 'onSubmit' method...");
}
DefectVarity defectVarity = (DefectVarity) command;
boolean isNew = (defectVarity.getVarityId() == null);
Locale locale = request.getLocale();
if (request.getParameter("delete") != null) {
defectVarityManager.removeDefectVarity(defectVarity.getVarityId().toString());
saveMessage(request, getText("defectVarity.deleted", locale));
} else {
List defectParameters = new ArrayList();
List defectParametersFromForm = defectVarity.getParameters();
for (int i = 0; i < defectParametersFromForm.size(); i++) {
Parameter parameter = (Parameter) defectParametersFromForm.get(i);
defectVarityManager.evict(parameter);
defectParameters.add(parameterManager.getParameter(parameter.getParameterId().toString()));
}
defectVarity.setParameters(defectParameters);
Integer materialId = defectVarity.getMaterial().getMaterialId();
if (!materialId.equals(new Integer(-1))) {
defectVarity.setMaterial(materialManager.getMaterial(materialId.toString()));
}
defectVarityManager.saveDefectVarity(defectVarity);
String key = (isNew) ? "defectVarity.added" : "defectVarity.updated";
saveMessage(request, getText(key, locale));
if (defectVarity.isEdited()) {
return new ModelAndView("redirect:updating.html?id=" + defectVarity.getVarityId() + "&fieldId=" + request.getParameter("fieldId"));
}
}
return new ModelAndView("redirect:" + defectVarity.getDocLocation());
}