@RequestMapping(value = "/question/{id}", params = "answer", method = RequestMethod.GET) public String answerQuestionForm(@PathVariable("id") Long id, Model model) { Question question = questionService.findById(id); QuestionAnswer questionAnswer = new QuestionAnswer(); questionAnswer.setCreationDate(question.getCreationDate()); questionAnswer.setName(question.getName()); questionAnswer.setEmail(question.getEmail()); questionAnswer.setPhone(question.getPhone()); questionAnswer.setQuestion(question.getQuestion()); questionAnswer.setAnswer(""); System.out.println(questionAnswer.getAnswer()); model.addAttribute("questionAnswer", questionAnswer); return "admin/questionAnswer/question"; }
@RequestMapping(value = "/question/{id}", params = "answer", method = RequestMethod.POST) public String answerQuestion( @PathVariable("id") Long id, QuestionAnswer questionAnswer, RedirectAttributes redirectAttributes, Locale locale) { questionAnswer.setAnswer(questionAnswer.getAnswer().substring(1)); Question question = questionService.findById(id); questionAnswer.setCreationDate(question.getCreationDate()); questionAnswer.setName(question.getName()); questionAnswer.setEmail(question.getEmail()); questionAnswer.setPhone(question.getPhone()); questionAnswerService.addQuestionAnswer(questionAnswer); questionService.deleteQuestion(id); redirectAttributes.addFlashAttribute( "message", new Message( "success", messageSource.getMessage("question_answer_save_success", new Object[] {}, locale))); return "redirect:/admin/questionAnswer"; }
@RequestMapping(value = "/{id}", params = "edit", method = RequestMethod.POST) public String answerQuestionEdit( @PathVariable("id") Long id, QuestionAnswer questionAnswer, Model model, RedirectAttributes redirectAttributes, Locale locale) { QuestionAnswer questionAnswerTmp = questionAnswerService.findById(id); if (questionAnswer.getAnswer() == "" || questionAnswer.getAnswer() == null) { Question question = new Question(); question.setCreationDate(questionAnswerTmp.getCreationDate()); question.setPhone(questionAnswerTmp.getPhone()); question.setEmail(questionAnswerTmp.getEmail()); question.setName(questionAnswerTmp.getName()); question.setQuestion(questionAnswerTmp.getQuestion()); questionService.addQuestion(question); questionAnswerService.deleteQuestionAnswer(id); } else { questionAnswer.setCreationDate(questionAnswerTmp.getCreationDate()); questionAnswer.setName(questionAnswerTmp.getName()); questionAnswer.setEmail(questionAnswerTmp.getEmail()); questionAnswer.setPhone(questionAnswerTmp.getPhone()); questionAnswer.setId(questionAnswerTmp.getId()); questionAnswerService.editQuestionAnswer(questionAnswer); } redirectAttributes.addFlashAttribute( "message", new Message( "success", messageSource.getMessage("question_answer_save_success", new Object[] {}, locale))); return "redirect:/admin/questionAnswer"; }