java - Spring 4 Attribute 'items' 必须是数组、Collection或Map

标签 java spring jsp spring-mvc

我在 Spring 4 中创建 Combobox 项时出现此错误。

java.lang.IllegalArgumentException: Attribute 'items' must be an array, a Collection or a Map
    org.springframework.web.servlet.tags.form.AbstractMultiCheckedElementTag.writeTagContent(AbstractMultiCheckedElementTag.java:234)
    org.springframework.web.servlet.tags.form.AbstractFormTag.doStartTagInternal(AbstractFormTag.java:84)

...

我有 POJO 类 Student :

    public class Student {
        @Size(min=3, max=30)
        private String firstName;

        @Size(min=3, max=30)
        private String lastName;

        @NotEmpty
        private String sex;

        @DateTimeFormat(pattern = "dd/MM/yyyy")
        @Past @NotNull
        private Date dob;

        @Email @NotEmpty
        private String email;

        @NotEmpty
        private String section;

        @NotEmpty
        private String country;

        private boolean firstAttempt;

        @NotEmpty
        private List<String> subjects = new ArrayList<String>();
...

我在我的 Controller 中创建方法并用 @ModelAttribute 注释它

@ModelAttribute("sections")
    public List<String> initializeSections() {
        List<String> sections = new ArrayList<String>();
        sections.add("Graduate");
        sections.add("Post Graduate");
        sections.add("Research");

        return sections;
    }

这是我的 JSP:

...
<div class="row">
                <div class="form-group col-xs-12">
                    <label class="col-xs-3" for="section">Section</label>
                    <div class="col-xs-7">
                        <form:radiobuttons path="section" items="${sections}"/>
                        <div class="has-error">
                            <form:errors path="section" class="help-inline" />
                        </div>
                    </div>
                </div>
            </div>
...

当我运行时,我收到上面的错误消息。 如何解决?缺少什么?

最佳答案

Answer ✓

I missing one thing, i have to add this isELIgnored="false", i found this according instruction from @JB Nizet to print out my EL. If you create webapp project from Maven, you must declare isELIgnored="false" manually.

Thank you.

关于java - Spring 4 Attribute 'items' 必须是数组、Collection或Map,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32805369/

相关文章:

java - 如何使用java连接到远程计算机上的Mysql DB。 DB计算机所在的网络上有许多具有相同公共(public)IP的计算机吗?

java - Spring ActiveMQ 问题

java - 如何有条件地将图像附加到表格中的单元格值。它在 JSP 中,并且使用表格的显示标签

java - JSON.解析: Unexpected character error in Javascript

java - 从非 servlet 类(来自外部 jar)引用 WEB-INF 中的文件

java - 输出为 "NaN"

java - 使用 Swing 创建图像是线程安全的吗?

java - 匿名用户的 Tomcat/spring session 管理

java - 基于 URL 参数的 Spring Security REST API 角色

java - 提交表单后返回上一页(Spring/Hibernate)