1

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. Explanation : 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 :(

1
  • Hope it will help you similar problem Commented May 31, 2017 at 21:31

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.