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

时间:2011-04-05 07:00:04

标签: java jsf uirepeat

假设我有以下课程

class Book{
    String author;
    String title;
}

我检索了Book(List<Book>)的列表,我希望将其显示在像

这样的表中
author1:
    title1
    title11

author2:
    title2
    title22
    title222

我正在考虑创建一个hashmap mapping author =&gt;书籍清单,但正如我在SO中所读到的,不支持hashmap h:数据表,也不是ui:repeat。

有关如何实现这一目标的任何提示?

谢谢。

PS:我正在使用jsf 1.2

随意提出更好的标题

1 个答案:

答案 0 :(得分:2)

我认为您必须调整数据模型才能将其转换为h:dataTable

我建议创建一个包含书籍列表的作者:

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

然后你可以基于List<Author> authorList(未经测试)构建嵌套的dataTable:

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