I'm new at Spring Boot and I face huge difficulties for binding object from a view with ThymeLeaf to a List in my Controller. I explain : I got a Form for create events, in this Form there are checkboxes generated dynamically with a List of "Enfant" (listEnfant) stored in the database :
GET REQUEST @Controller public class EventController {
@RequestMapping(value="/createEvent",method=RequestMethod.GET)
public String Affichercreationcotisation(Model model,Enfant enfant){
List<Enfant> listEnfant = gardeMetier.findEnfantfamille();
model.addAttribute("listEnfant", listEnfant);
List<String> ListEnfants = new ArrayList<>(0);
model.addAttribute("listEnfantsChoisis", ListEnfants);
return "eventForm";
}
When I run the Application there is no problem with the GET Request I got the checkboxes which are expected
As you can see i created an empty List which I could use to store selected checkboxes objects
HTML
<th:block th:each="e :${listEnfant}">
<input type="checkbox" th:field="" />
<label th:text="${e.name}"></label>
</th:block>
I don't know and don't find (or understand) what to do with my post request and how to configure the th:field to put the selected checkboxes objects in a List when the Form is submitted
@RequestMapping(value="/saveEvent",method=RequestMethod.POST)
public String saveEvent() {
}
I hope someone will help me because I'm looking for the solution for hours now :(
Aucun commentaire:
Enregistrer un commentaire