在 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>
当我打开 View 时,我会看到选中的复选框。
但是如何取消选中此复选框呢?
最佳答案
问题出在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>
关于forms - 表格:checkboxes unchecked by default,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23686214/