I am using the spring form:checkbox tag to display a set of values using the tag below
<c:forEach var="barrier" items="${barriersList}" varStatus="idx">
<label class="${barrier.display=='Y' ? 'block-label' : 'block-label disabled'}" for="barrier${barrier.id}" }">
<form:checkbox path="barriers" value="${barrier.id}" id="barrier${barrier.id}"
disabled="${barrier.display=='N'}" />${barrier.barrier}
</label>
</c:forEach>
this tag is wrapped in a form which has a model attribute of testDto.
<form:form method="post" accept-charset="UTF-8" action="${action}"
modelAttribute="testDto">
the testDto class has a attribute that maps to the path of the form checkbox tag
private List<Barrier> barriers = new ArrayList<Barrier>();
i load the barriersList from within my controller and set it on the modelandview spring object
mav.addObject("barriersList", dataService.getBarriers());
I can select the checkboxes and save the data into the database but the issue is when i want to edit the checkboxes. In the foreach loop I am looping over the barriersList which does not have my selected checkboxes. It just displays the available options.
When I am making a return trip from the database I do set the selected checkboxes on my testDto but my issue is how do I show the checked selections and the unchecked selections when I load the page up for edit as the user may want to change what has been selected.
If my foreach block loops through items in testDto.barriers then it will only show the checkboxes that exist in that list which is not all of them. When I loop through the barriersList object is shows all the selections but none of them are checked.
Any ideas or pointers
Thanks
Aucun commentaire:
Enregistrer un commentaire