Spring + Thymeleaf. Не передается значение в модальное окно

Ковыряю Spring-mvc и thymeleaf. На странице отображается список пользователей, пользователя можно редактировать (должно вызываться модальное окно с заполненным id пользователя) Проблема - в модальное окно не передается значение id, а передается "1" для каждого пользователя. При этом в source-code страницы значения id заполнены корректно.

Html проблемного места:

<table>
<thead>
    <tr>
        <th>Name</th>
        <th>Age</th>
    </tr>
</thead>
<tbody>
    <tr th:each="user:${users}">
        <td th:text="${user.name}"></td>
        <td th:text="${user.age}"></td>
        <td>
            <button><a href="#updateForm">Изменить</a></button>
            <div id="updateForm">
                <form th:action="@{/updateUser}" th:object="${userUpdate}" method="post">
                    <input type="hidden" th:value="${user.id}" name="id" />
                    <table>
                        <tr>
                            <th>Name</th>
                            <td><label><input type="text" th:field="*{name}"></label></td>
                        </tr>
                        <tr>
                            <th>Age</th>
                            <td><label><input type="number" th:field="*{age}" min="1"></label></td>
                        </tr>
                        <tr>
                            <th><input type="submit" value="Ok"/></th>
                            <th><button><a href="#" class="close">Cancel</a></button></th>
                        </tr>
                    </table>
                </form>
            </div>
        </td>
        <td>Удалить</td>
    </tr>
</tbody>
</table>

Контроллер :

@Controller
@RequestMapping("/")
public class UserController {

    final UserService service;

    public UserController(UserService service) {
        this.service = service;
    }

    @GetMapping
    public String showAll(Model model) {
        model.addAttribute("users", service.getAllUsers());
        model.addAttribute("userUpdate", new User());
        return "users";
    }

    @PostMapping("/updateUser")
    public String updateUser(@ModelAttribute("user") User user) {
        service.updateUser(user);
        return "redirect:/";
    }
}

Значение поля в модальном окне и в source-code (поле сделал видимым)

Я понимаю, что проще и правильнее было бы сделать другим способом (например, @RequestMapping по id), в данный момент я хочу решить именно таким способом.

Вопрос - в чем причина такого странного поведения?)


Ответы (0 шт):