【发布时间】:2014-12-30 18:56:07
【问题描述】:
这是我的sn-ps代码:
车辆类别:
// Duplicates
private Boolean regCard = true;
private Boolean decal;
private Boolean title;
public Boolean getRegCard() {
return regCard;
}
public void setRegCard(Boolean regCard) {
this.regCard = regCard;
}
public Boolean getDecal() {
return decal;
}
public void setDecal(Boolean decal) {
this.decal = decal;
}
public Boolean getTitle() {
return title;
}
public void setTitle(Boolean title) {
this.title = title;
}
百里香:
<form method="post" th:action="${flowExecutionUrl}" th:object="${customerModel.vehicle}">
<div class="duplicates">
<ul>
<li><label>What do you need to duplicate?</label>
<div class="regTitle">
<label>Registration Card
<input type="checkbox" th:field="*{regCard}"/>
</label>
<label>Decal
<input type="checkbox" th:field="*{decal}"/>
</label>
<div th:switch="*{vehicleType}">
<div th:case="'BR'">
<label>Title
<input th:type="checkbox" th:field="*{title}"/>
</label>
</div>
</div>
</div>
</li>
</ul>
<div class="clear"></div>
</div>
<div class="btm-btn-row">
<div class="btm-btn-left">
<a th:href="@{'~' + ${flowExecutionUrl}(_eventId='back')}">back</a>
</div>
<div class="btm-btn-right">
<input type="submit" value="continue" name="_eventId_continue" />
</div>
</div>
</form>
生成的 HTML:
<form method="post" action="/IllinoisRVSWeb/main-flow?execution=e1s4">
<div class="duplicates">
<ul>
<li><label>What do you need to duplicate?</label>
<div class="regTitle">
<label>Registration Card
<input type="checkbox" id="vehicle.regCard1" name="vehicle.regCard" value="true" checked="checked" /><input type="hidden" name="_vehicle.regCard" value="on" />
</label>
<label>Decal
<input type="checkbox" id="vehicle.decal1" name="vehicle.decal" value="true" /><input type="hidden" name="_vehicle.decal" value="on" />
</label>
<div>
<div>
<label>Title
<input type="checkbox" id="vehicle.title1" name="vehicle.title" value="true" /><input type="hidden" name="_vehicle.title" value="on" />
</label>
</div>
</div>
</div>
</li>
</ul>
<div class="clear"></div>
</div>
<div class="btm-btn-row">
<div class="btm-btn-left">
<a href="/IllinoisRVSWeb/main-flow?execution=e1s4&_eventId=back">back</a>
</div>
<div class="btm-btn-right">
<input type="submit" value="continue" name="_eventId_continue" />
</div>
</div>
</form>
问题:
提交时永远不会设置布尔值。 我试过另一种方式。使用 List 对象并将该变量绑定到复选框,并为每个复选框使用正确的 th:value="'SOMETEXT'" 。但该对象也保持为空。
如您所见,我事先将一个值设置为 true 以查看它是否会显示在 html 端。它是成功的。所以它至少会检索该值,但如果它改变了它就不会设置它。
另外,如您所见,我尝试使用“th:value="checkbox"” 来查看是否有帮助。它没有。
Thymeleaf 版本 2.1.4
春季 4.1.4
Spring WebFlow 2.4.0
任何帮助或提示都会很棒。
谢谢
【问题讨论】:
-
在我正在开发的网站的另一个页面中,我能够成功使用复选框并将正确的布尔值发送到后端。我正在比较这两个页面,看看我做了什么不同,但乍一看没有发现任何差异。