从ui:repeat使用的列表项中获取的表头



假设我有如下的类Book

class Book{
    String author;
    String title;
}

我检索Book (List<Book>)的列表,我想将它显示在一个表中,如

author1:
    title1
    title11
author2:
    title2
    title22
    title222

我想创建一个hashmap映射author =>图书列表,但是,正如我在SO中所读到的,hashmap不支持H:datatable,而不是ui:repeat

关于如何做到这一点有什么建议吗?

谢谢。

PS:我使用jsf 1.2

请随意提出更好的标题

我认为你必须调整你的数据模型,以使其进入h:dataTable

我建议用一个图书列表创建一个类Author:

class Author{
  String name;
  List<Book> books;
  ..
  // getters and setters
}

然后你可以基于List<Author> authorList(未测试)构建一个嵌套的数据表:

<h:dataTable value="#{bean.authorList}" var="author">
  <h:column>
    <h:outputText value="#{author.name}"/>
    <h:dataTable value="#{author.books}" var="book">
      <h:column>
        <h:outputText value="#{book.title}"/>
      </h:column>
    </h:dataTable>  
  </h:column>
</h:dataTable>

最新更新