forms - 表格:checkboxes unchecked by default

标签 forms spring spring-mvc checkbox jspx

在 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>

当我打开 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/

相关文章:

java - 无法实例化 TestExecutionListener

java - Jackson 2 和 Spring Autowired bean

mysql - 保存非英语字符时出现问题

java - Spring Boot (1.3.5) - 默认错误 View

java - 将表单单选值发送到 Java servlet,返回 null

forms - Elementor 表单自定义 webhook 返回 "error"消息

ruby-on-rails - Ruby on Rails 2 表单样式 - 简单问题

java - 默认情况下,依赖于其他 bean 的 Spring bean 是否会获得这些 bean 的单例版本?

php - 如何使用 PHP 将 HTML 表单数据传递给 MYSQL 数据库并将数据返回给浏览器

java - 如何在 Spring 中使用基于注释的属性