Witajcie.
Mam problem z przekazaniem zaznaczonych checkboxem pozycji do kontrolera.
Fragment klasy konrolera
@RequestMapping(value = "/addmedicaments/{id}")
public ModelAndView addMedicaments(@PathVariable int id, Principal principal)
{
ModelAndView mav = new ModelAndView("diseaseAddMedicaments");
String name = principal.getName();
User user = userService.findByName(name);
mav.addObject("medicaments", medicamentService.findByUser(user));
return mav;
}
@RequestMapping(value = "/aaddmedicaments/do")
public ModelAndView addMedicamentsSubmit(List<Medicament> medicaments, Principal principal)
{
ModelAndView mav = new ModelAndView("redirect:/disease/list.html");
return mav;
oraz jsp
<form:form method="POST" modelAttribute="medicaments" action="do.html">
<table id="myTable">
<thead>
<tr>
<td>dodaj</td>
<td>nazwa leku</td>
<td>opakowanie</td>
<td>data waznosci</td>
</tr>
</thead>
<tbody>
<c:forEach items="${medicaments}" var="medicament">
<tr>
<td><form:checkbox path="medicaments" value="${medicament}"/></td>
<td>${medicament.medicamentDb.name}</td>
<td>${medicament.medicamentDb.pack}</td>
<td>${medicament.dateExpiration}</td>
</tr>
</c:forEach>
</tbody>
</table>
<input type="submit" value="Dodaji"/>
</form:form>
</div>
Dostaje błąd przy próbie wyświetlenia strony.
Invalid property 'medicaments' of bean class [java.util.ArrayList]: Bean property 'medicaments' is not readable or has an invalid getter method: Does the return type of the getter match the parameter type of the setter?
Nie mam pojęcia jak przekazać z powrotem listę obiektów, które przekazałem do widoku.
Czy ktoś ma pomysł jak to zrobić?
Generalnie uczę się programować od jakiegoś czasu więc z góry przepraszam za błędy merytoryczne, językowe, kodowe, w nazewnictwie, itp.