Zaczynam naukę springa.
Wyświetlam w /journeys listę moich journey, dodanych do bazy, w taki sposób:
<table>
<tr th:each="trip : ${trips}">
<td th:text="${trip.title}"></td>
<td th:text="${trip.destination}"></td>
<td th:text="${trip.id}"></td>
</tr>
</table>
W nowej komórce chciałbym button-delete przy każdym wylistowanym obiekcie, żeby po kliknięciu, żądany obiekt usuwać i odświeżać stronę. Wyczytałem na internetach, że muszę zrobić to przy pomocy formularza, polem typu hidden, więc popełniłem coś takiego:
`<table>
<tr th:each="trip : ${trips}">
<td th:text="${trip.title}"></td>
<td th:text="${trip.destination}"></td>
<td th:text="${trip.id}"></td>
<form th:action="@{/journeys}" th:object="${trip}" method="post">
<input type="hidden" th:field="${id}" />
<button type="submit">Delete</button>
</form>
</tr>
</table>
Mój kontroler wygląda następująco:
@RequestMapping(value = {"/journeys"}, method = RequestMethod.GET)
public String journeysPage(Model model){
return "journeysSite";
}
@RequestMapping(value = {"/journeys"}, method = RequestMethod.POST)
public String journeysPageTripDeleting(@ModelAttribute Trip trip){
tripRepository.delete(trip.getId());
return "redirect:/journeys";
}
Oczywiście coś schrzaniłem i przy próbie wejścia na /journeys dostaję:
java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'id' available as request attribute
Mógłby ktoś zarzucić jakąś poradą gdzie popełniłem błąd?