Iterate over HashMap.values ​​() in JSF + Facelets

I am using JSF / Facelets and I am trying to iterate over some Document objects (user object) that are stored in a HashMap. When the page loads, I get an error “Property name” not found by type java.util.HashMap $ Values. Here is what's in my bean support:

private Map<String, Document> documents = new HashMap<String, Document>();

public Collection<Document> getDocuments(){
    return documents.values();
}

And on my xhtml page:

<h:dataTable id="documentTable"
    value="#{DocumentManager.allDocuments}"
    var="doc" rowClasses="list-row-odd, list-row-even"
    headerClass="table-header" styleClass="bordered">

    <h:column id="col_name">
         <f:facet name="header">Name</f:facet>
         ${doc.name}
    </h:column>
</h:dataTable>

If I change the getDocuments function to the following, it works (this means the table is displayed without errors), but I'm not sure why I need to put the values ​​in a list to display the JSF / Facelets page.

public List<Document> getDocuments(){
    List<Document> rtrn = new ArrayList<Document>();
    for(Document doc : documents.values())
        rtrn.add(doc);
    return rtrn;
}

Can't I iterate through the collection?

+5
source share
1 answer

, , - dataTable . MyFaces 1.2 Spec value :

EL , .

, EL .

  • DataModel .
  • Object[], java.util.List, java.sql.ResultSet javax.servlet.jsp.jstl.sql.Result DataModel, , .
  • DataModel .

, , Set, . , , , - .

, HashSet.values ​​(), , , . , , , . .

, , , datatable , Collection "name".

+9

All Articles