c: foreach utilizzando List: deve valutare a una raccolta, Map, Array, o null
-
13-09-2019 - |
Domanda
Così sto cercando di loop su un List<MyClass>
per la visualizzazione nella visualizzazione della mia applicazione primavera webflow. Tuttavia ho l'errore deve restituire una collezione, Map, Array, o nullo.
<c:forEach items="#{orderedStuff}" var="a">
#{a.PrettyName}test
</c:forEach>
Inoltre ho provato $ al posto di #.
Ecco la mia definizione di flusso XML.
<view-state id="bookToc">
<on-render>
<evaluate expression="stuffService.getOrderedStuff(stuff)" result="viewScope.orderedStuff"
result-type="dataModel" />
</on-render>
</view-state>
E la funzione che restituisce l'elenco delle sezioni.
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;
}
La cosa è, questo codice FUNZIONA
<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>
Soluzione
Penso che si dovrebbe chiamare dal campo di applicazione che si sta creando
Prova
<c:forEach items="#{bookTok.orderedStuff}" var="a">
E, perché sono le vostre liste finale?
Altri suggerimenti
Credo che <c:forEach...
ha bisogno di uno di quei tipi. Hai provato a convertirlo in un array, per esempio:
// Create an array containing the elements in a list
Stuff[] array = (Stuff[])orderedStuff.toArray(new Stuff[orderedStuff.size()]);
Non ho lavorato in Java per un po ', mi perdoni se questo è fuori strada.
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow