Here is tricky issue, I have next jspx:
<form:form modelAttribute="employee" id="employeeUpdateForm" method="post">
<form:select path="departmentId">
<form:options items="${departments}" />
</form:select>
<button type="submit">Save</button>
<button type="reset">Reset</button>
</form:form>
and my updateForm method:
@RequestMapping(value = "/{id}", params = "form", method = RequestMethod.GET)
public String updateForm(@PathVariable ("id") Long id, Model uiModel) {
uiModel.addAttribute("employee", employeeService.findById(id));
List<Department> departments = employeeService.getAllDepartments();
uiModel.addAttribute("department", departments);
return "staff/update";
}
"department" has two fields: departmentId (int) and divisionName (String).
So, "employee" and "department" are two different objects, I would like to have ability to populate field related to "employee" (departmentId) with string representations from "department". Their departmentId match one another. Once certain department is chosen its id is putting to employee.departmentId.
Thanks in advance!