【问题标题】:form:checkboxes unchecked by default表单:复选框默认未选中
【发布时间】:2014-05-16 03:15:57
【问题描述】:
在 jspx 我有:
<form:form commandName="wordingPractice" autocomplete="off">
<input type="hidden" name="_flowExecutionKey" value="${flowExecutionKey}"/>
<form:checkboxes items="${wordingPractice.answers}" path="answers"
delimiter="<br/>" checked=""/>
</form:form>
当我打开视图时,我会看到选中的复选框。
但是如何取消选中此复选框?
【问题讨论】:
标签:
forms
spring
spring-mvc
checkbox
jspx
【解决方案1】:
问题出在 path="answers" 中。 answers 是要显示为复选框的项目列表,如项目中所述。您的路径也是应该包含选定答案的答案。因此路径值与项目匹配,因此所有复选框都被选中。
为了克服这个问题,创建数组 selectedAnswers 来保存 wordingPractice 中所选值的逗号分隔值:
private String [] selectedAnswers;
//setters and getters
把jsp改成:
<form:form commandName="wordingPractice" autocomplete="off">
<input type="hidden" name="_flowExecutionKey" value="${flowExecutionKey}"/>
<form:checkboxes items="${wordingPractice.answers}" path="selectedAnswers"/>
</form:form>