throws Exception {
if (log.isDebugEnabled()) {
log.debug("entering 'onSubmit' method...");
}
Question question = (Question) command;
boolean isNew = (question.getQuestionId() == null);
Locale locale = request.getLocale();
if (request.getParameter("delete") != null) {
questionManager.removeQuestion(question.getQuestionId().toString());
saveMessage(request, getText("question.deleted", locale));
} else {
Integer questionTypeId = question.getQuestionType().getQuestionTypeId();
if (!questionTypeId.equals(new Integer(-1))) {
question.setQuestionType(questionTypeManager.getQuestionType(questionTypeId.toString()));
}
Integer documentTypeId = question.getDocumentType().getDocumentTypeId();
if (!documentTypeId.equals(new Integer(-1))) {
question.setDocumentType(documentTypeManager.getDocumentType(documentTypeId.toString()));
} else {
question.setDocumentType(null);
}
if (question.getQuestionType().getQuestionTypeId().equals(new Integer(0))) {
List constructionTypeList = new ArrayList();
List constructionTypeListFromForm = question.getConstructionTypes();
for (int i = 0; i < constructionTypeListFromForm.size(); i++) {
ConstructionType constructionType = (ConstructionType) constructionTypeListFromForm.get(i);
constructionTypeList.add(constructionTypeManager.getConstructionType(constructionType.getConstructionTypeId().toString()));
}
question.setConstructionTypes(constructionTypeList);
}
List answerListFromForm = question.getAnswers();
for (int i = 0; i < answerListFromForm.size(); i++) {
Answer answer = (Answer) answerListFromForm.get(i);
answer.setQuestion(null);
answerManager.saveAnswer(answer);
}
questionManager.saveQuestion(question);
for (int i = 0; i < answerListFromForm.size(); i++) {
Answer answer = (Answer) answerListFromForm.get(i);
answer.setQuestion(question);
answerManager.saveAnswer(answer);
}
String key = (isNew) ? "question.added" : "question.updated";
saveMessage(request, getText(key, locale));
if (question.isEdited()) {
return new ModelAndView("redirect:updating.html?id=" + question.getQuestionId() + "&fieldId=" + request.getParameter("fieldId"));
}
}
return new ModelAndView("redirect:" + question.getDocLocation());
}