I'm using spring mvc with thymeleaf to save a form with a dropdown value. The problem is when saving, I get the error 400 bad request only when I append the foreign key field in the form as a dropdown with th:field="studentTypeCode".
<select id="typeSelect" class="text_box" th:field="*{studentTypeCode}">
<div th:each="studentTypeCode : ${studentTypeCodes}" th:remove="tag">
<option th:value="${studentTypeCode.typeId}" th:text="${studentTypeCode.typeName}" />
</div>
</select>
Student.java
public class Student{
private String name;
//... other fields
//..
StudentTypeCode studentTypeCode;
//getters and setters
}
And in the controller I get the Student object using the th:object with the
@ModelAttribute Student student param. Saving the form throws me 400 bad request since the field studentTypeCode is not correctly sent in the request.