代码之家  ›  专栏  ›  技术社区  ›  Scott Schulthess

c: foreach使用列表:必须计算为集合、映射、数组或null

  •  1
  • Scott Schulthess  · 技术社区  · 17 年前

    List<MyClass>

        <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 回复  |  直到 14 年前
        1
  •  2
  •   Jesse    17 年前

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

    尝试

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

        2
  •  0
  •   karim79    17 年前

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

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

    我已经有一段时间没有使用Java了,如果这太离谱了,请原谅我。

    推荐文章