I'm trying to do a form action where I show selected lists for each of some grouped values. After the user chooses a value in one of these lists I want to put the name of this object into a button link as a parameter but the parameter values are empty. I don't know how can I do it.
Here is my code for that:
In my controller:
@RequestMapping(value="/teacher/depts", method=RequestMethod.GET)
public String depts(Model model) {
model.addAttribute("deptsfields", fieldOfStudyService.findAllFieldsForAllDepartments());
model.addAttribute("field", new FieldOfStudy());
return "teacher/depts";
}
@RequestMapping(value="/deptsfields", method=RequestMethod.POST)
public String deptsfields(@ModelAttribute(value="field") FieldOfStudy field) {
return "teacher/depts";
}
And my html page:
<form action="#" th:action="@{/deptsfields}" th:object="${field}" method="post">
<table>
<tr>
<th>Wydział</th>
<th>Kierunek</th>
</tr>
<tr th:each="entry : ${deptsfields}">
<td th:text="${entry.getKey().details.departmentFullName}"
th:value="${entry.getKey().details.departmentFullName}"
th:field="*{details.department.details.departmentFullName}"></td>
<td>
<select id="fieldslist" class="form-control" th:field="*{details.fieldOfStudyName}">
<option selected="selected" value="">Wybierz...</option>
<option th:each="field : ${entry.getValue()}" th:value="${field.details.fieldOfStudyName}" th:text="${field.details.fieldOfStudyName}"></option>
</select>
</td>
</tr>
</table>
<a th:href="@{/teacher/groups(field=${field.details.fieldOfStudyName}, dept=${field.details.department.details.departmentFullName})}" class="btn btn-info" role="button">Dalej</a>
</form>
After click the button I'm redirected to this page:
http://localhost:8080/teacher/groups?field={here should be name but is empty}&dept={here should be name but is empty}
What I'm doing wrong?