views:

1288

answers:

2

So I'm trying to loop over a List<MyClass> for display in the view of my spring webflow application. However I get the error Must evaluate to a Collection, Map, Array, or null.

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

I've also tried $ instead of #.

Here is my xml flow definition.

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

And the function that returns the list of sections.

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;
}

The thing about it is, this code DOES WORK

<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>
A: 

I guess <c:forEach... needs one of those types. Have you tried converting it to an array, e.g:

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

I haven't worked in Java for a while, forgive me if this is way off.

karim79
isn't ArrayList/List a collection? That's what's confusing me.
scottschulthess
+1  A: 

I think you would have to call from the scope that you're creating

Try

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

And, why are your lists final?

Jesse
final just means you can't assign a new List to the list (e.g. orderedStuff) reference. That is fine here.
Matthew Flaschen