表单:默认情况下复选框未选中



在jspx我有:

 <form:form commandName="wordingPractice" autocomplete="off">
    <input type="hidden" name="_flowExecutionKey" value="${flowExecutionKey}"/>
    <form:checkboxes items="${wordingPractice.answers}" path="answers" 
          delimiter="&lt;br/&gt;" checked=""/>
</form:form>

当我打开视图时,我看到选中的复选框。

但是如何使这个复选框不被选中呢?

问题在path="answers"。answers是要显示为复选框的项目列表,如items中所述。你的路径也是答案,它应该包含选定的答案。因此路径值与项匹配,因此所有复选框都被选中。为了解决这个问题,创建数组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>

最新更新