vendredi 24 août 2018

Checkboxes with Thymeleaf e SpringMVC

I'm trying to create a multi checkbox, but it doesn't work, where's the error? This is my code:

checkorganization.html

<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
 <form action="#" th:action="@{/checkorg}" th:object="${organization}" 
method="post">
<ul>
<li th:each="org : ${organizations}">
<input type="checkbox" th:field="*{organizations}" th:value="${org}" />
</li>
</ul>
</form>
</body>
</html>
    <p><input type="submit" value="Submit" /> <input type="reset" value="Reset" /></p>
</form>
</body>
</html>

OrganizationController.java

@Controller
public class OrganizationController {
@Autowired
private OrganizationRepository organizationRepository;
@GetMapping("/checkorg")
public String checkOrg (Model model) {
       List<Organization> organizations = new ArrayList<Organization>();
       organizations = organizationRepository.findAll();
       Iterator<Organization> iterator = organizations.iterator();
       while (iterator.hasNext()) {
           model.addAttribute("organizations", iterator.next()); 
       }    
       return "checkorganization";
}

}




Aucun commentaire:

Enregistrer un commentaire