[英]Hidden input in thymeleaf with wrong value
in GET method I'm adding these to the model: 在GET方法中,我将这些添加到模型中:
model.addAttribute("team", team);
model.addAttribute("players", team.getPlayers());
model.addAttribute("inviting", new InvitingPlayerToTeam());
And a fragment of view with this model: 这个模型的一部分视图:
<div id="news" th:fragment="playerList">
<span>Nazwa: </span>
<span th:text="${team.name}">nazwa teamu</span>
<br>
<span th:each="player : ${players}" th:utext="${player.username} + '</br>'">-</span>
<br><br>
<form method="POST" th:action="@{/team/invitePlayer}" th:object="${inviting}">
Nazwa <input type="text" th:field="*{username}">
<input type="hidden" th:field="*{teamId}" th:value="${team.id}">
<br>
<input type="submit" value="Zaproś">
</form>
</div>
What is wrong? 怎么了? In post method field
inviting.username
has good value, but inviting.teamId
is 0
. 在post方法字段中,
inviting.username
具有良好的价值,但inviting.teamId
为0
。 Where is the problem? 问题出在哪儿?
Just remove th:value="${team.id}"
. 只需删除
th:value="${team.id}"
。 You do not need to set this value again. 您无需再次设置该值。
You should set up your form backing bean with the correct values in your controller. 您应该在控制器中使用正确的值设置表单支持bean。
inviting.setTeamId(...)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.