При попытке собрать HashMap со значениями Long - ключ , Boolean - значение выскакивает ошибка "Invalid property '45' of bean class [java.util.HashMap]: Bean property '45' is not readable or has an invalid getter method: Does the return type of the getter match the parameter type of the setter?" (45 в данном случае - ключ по которому надо занести значение)
Мой контроллер:
@Controller
public class FlowController {
@Autowired
private TestInterfaceService testService;
@Autowired
private ResultCalcInterfaceService resCalc;
@Autowired
private UserService userService;
@Autowired
private SecurityService securityService;
@Autowired
private QuestionInterfaceService questionService;
@Autowired
private ResultInterfaceService resService;
@RequestMapping(value = "/testPassing/{id}", method = RequestMethod.GET)
public String testPassing(@PathVariable("id") long id, Model model) {
Test test = this.testService.getFullTestById(id);
model.addAttribute("ourTest", test);
return "testPassing";
}
@RequestMapping(value = "/passing/{id}")
public String startPassing(@PathVariable("id") long id, @RequestParam(required = false) Integer qId, Model model) {
Test test = this.testService.getFullTestById(id);
Date date = resService.addResult(test, userService.findByUsername(securityService.getName()));
model.addAttribute("passingTest", test);
int pageSize = test.getQuestions().size();
List<Question> questions = test.getQuestions();
model.addAttribute("questionSize", test.getQuestions().size());
SimpleDateFormat formatter = new SimpleDateFormat("MMM d, yyyy HH:mm:ss", Locale.ENGLISH);
String dateString = formatter.format(date);
model.addAttribute("ourDate", dateString);
model.addAttribute("Long", new Long(0));
if (qId == null || qId < 1 || qId > pageSize) {
qId = 1;
model.addAttribute("questionId", questions.get(qId).getId());
model.addAttribute("question", questions.get(qId));
HashMap<Long, Boolean> listAnswers = questionService.getAnswerList(questions.get(qId));
model.addAttribute("listAnswers", listAnswers);
} else if (qId <= pageSize) {
model.addAttribute("questionId", qId);
model.addAttribute("question", questions.get(qId - 1));
HashMap<Long, Boolean> listAnswers = questionService.getAnswerList(questions.get(qId - 1));
model.addAttribute("listAnswers", listAnswers);
}
return "testPassing";
}
@RequestMapping(value = "/setAnswer/{questionId}", method = RequestMethod.GET)
public String setAnswer(@ModelAttribute("listAnswers") HashMap<Long, Boolean> listAnswers,
@PathVariable("questionId") long questionId, Model model) {
Question question = questionService.getQuestionById(questionId);
System.out.println(listAnswers);
HashMap<Long, Boolean> listAnswers2 = listAnswers;
resCalc.setAnswer(userService.findByUsername(securityService.getName()), question, listAnswers2);
Test test = question.getqTest();
return "redirect:/passing/" + test.getId();
}
}
Мой JSP :
<form:form
action="${pageContext.request.contextPath}/setAnswer/${questionId}"
modelAttribute="listAnswers" method="GET">
<table>
<c:forEach items="${listAnswers}" var="answer" varStatus="status">
<tr>
<td>${answer}</td>
<td><form:select path="${answer.key}" value="${answer.value}" /></td>
</tr>
</c:forEach>
</table>
<br />
<input type="submit" value="Save" />
</form:form>
П.с. если заменить form:select на input / select то в контроллер прилетает null а не лист выбора пользователя
Кофе для программистов: как напиток влияет на продуктивность кодеров?
Рекламные вывески: как привлечь внимание и увеличить продажи
Стратегії та тренди в SMM - Технології, що формують майбутнє сьогодні
Выделенный сервер, что это, для чего нужен и какие характеристики важны?
Для генерации метода в студии нажимаю Alt + insert, на что студия вообще не реагируетХоткей использую между методами в MainActivity
Есть метод, который принимает в качестве параметра имя класса, но как StringКак можно преобразовать этот String в нужный класс?
Добрый день, так как только начал изучать Spring и даже по аналогии сделал первое web-приложение, но все равно есть вопросы, и описание в инете...