c:foreach using List:必须求值为Collection,Map,Array或null

时间:2009-06-15 19:21:11

标签: java spring jsp jstl spring-webflow

所以我试图在我的spring webflow应用程序视图中循环显示List<MyClass>。但是我得到错误必须评估为Collection,Map,Array或null。

    <c:forEach items="#{orderedStuff}" var="a">
    #{a.PrettyName}test
    </c:forEach>

我也试过$而不是#。

这是我的xml流程定义。

<view-state id="bookToc">
    <on-render>
        <evaluate expression="stuffService.getOrderedStuff(stuff)" result="viewScope.orderedStuff"
            result-type="dataModel" />
    </on-render>
</view-state>

返回部分列表的函数。

public List<Stuff> getStuff(Stuff stuff) {
    final List<Stuff> orderedStuff= new ArrayList<Stuff>();

    final List<Stuff> sections = stuff.getStuff();
    PropertyComparator.sort(sections, new MutableSortDefinition("sortOrder", true, true));

    for (Section stuff : stuffs) {
        orderedStuff.add(stuff);
        this.addSubsectionsToOrderedStuff(stuff, orderedStuff);
    }

    return orderedStuff;
}

关于它的事情是,这段代码工作

<h:dataTable id="stuffList" value="#{orderedStuff}" var="s"
            rendered="#{not empty orderedStuff}">
            <h:column>
                <f:facet name="header">
                    Section Title
                </f:facet>
                #{s.prettyName}
                <h:dataTable value="#{s.chapters}" var="c" rendered="#{not empty s.chapters}">
                    <h:column>
                        <f:facet name="header">
                        Chapter Title
                        </f:facet>
                    #{c.title}
                    </h:column>
                </h:dataTable>              
            </h:column>
        </h:dataTable>  

2 个答案:

答案 0 :(得分:2)

我认为您必须从您正在创建的范围调用

尝试

 <c:forEach items="#{bookTok.orderedStuff}" var="a">

而且,为什么你的名单最终?

答案 1 :(得分:0)

我猜<c:forEach...需要其中一种类型。您是否尝试将其转换为数组,例如:

// Create an array containing the elements in a list
Stuff[] array = (Stuff[])orderedStuff.toArray(new Stuff[orderedStuff.size()]);

我有一段时间没有在Java工作过,请原谅我,如果这样的话。

相关问题