mercredi 2 novembre 2016

How to map a group of checkboxes back to a List<> Object?

I have a Controller that sends a model to a View with a list of objects resembling checkboxes.

Generic Controller:

@RequestMapping("someLink")
public String createForm(Model model, @ModelAttribute ("someForm") SomeForm 
form){
   form.addList(listOfCheckboxObjects);
   model.setAttribute ("someForm", form);
   return "path";
}

The checkbox list is mounted in a view (generic):

<c:forEach items="${someForm.list}" var="list">
            list.name
            <form:checkbox path="listAttributeNameInFormBean" value="${list.checked}"/>
            <br/>
</c:forEach>

Backed by a Checklist object:

public class Options{
   private String name;
   private Boolean checked;
   .. Getters and Setters
}

How to get those Options objects back into a list back into the form Model for processing?




Aucun commentaire:

Enregistrer un commentaire