I am sending a list of objects from controller method of spring mvc to thymeleaf view through model attribute and want to iterate the list in a view with table and i want to make each row a html form so that if i edit the row which represents the object in a list will update the object. But I am getting exception java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name ‘score’ available as request attribute. Can anyone help me to find out What mistake I am doing?
Handler Method
@GetMapping("/exams/update")
public String viewStudentUpdate(@RequestParam("subject") Integer id ,Model model)
{
Subject subject = serviceSubjectDao.getSubjectById(id);
List<Score> scores = serviceScoreDao.getScoreForSubject(subject);
model.addAttribute("scores",scores);
model.addAttribute("subjectName",subject);
model.addAttribute("PageName","StudentMarksUpdate");
return "Template";
}
Thymeleaf template
<table class="m-2 table table-bordered">
<thead>
<tr class="text-center">
<th scope="col">Student Name</th>
<th scope="col">CT-1</th>
<th scope="col">CT-2</th>
<th scope="col">INTERNAL</th>
<th scope="col">END SEMESTER</th>
<th scope="col">GRADE</th>
<th scope="col">EXAM DATE</th>
<th scope="col">UPDATE</th>
</tr>
</thead>
<tbody class="text-center">
<tr th:each="score : ${scores}">
<form th:action="@{/faculty/exams/update/process}" th:object="${score}" method="post">
<td th:text="${score.student.name}"><a th:href="@{/Student/profile/view(stId=${score.student.id})}" class="text-decoration-none">name</a></td>
<td><input type="number" name="ct1" id="ct1" th:field="*{ct1}"/></td>
<td><input type="number" name="ct2" id="ct2" th:field="*{ct2}"/></td>
<td><input type="number" name="internal" id="internal" th:field="*{internal}"/></td>
<td><input type="number" name="endSem" id="endSem" th:field="*{endSem}"/></td>
<td><input type="text" name="grade" id="grade" th:field="*{grade}"/></td>
<td><input type="date" name="examDate" id="examDate" th:field="*{examDate}"/></td>
<td><button type="submit" class="btn btn-warning">Update</button></td>
</form>
</tr>
</tbody>
</table>