【问题标题】: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="&lt;br/&gt;" 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>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-03-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-06-22
      • 2012-11-24
      • 2018-01-15
      相关资源
      最近更新 更多