【问题标题】:Table header taken from the list item used with ui:repeat表头取自与 ui:repeat 一起使用的列表项
【发布时间】:2011-04-05 07:00:03
【问题描述】:

假设我有以下课程书

class Book{
    String author;
    String title;
}

我检索了 Book (List<Book>) 的列表,我想将它显示在类似的表格中

author1:
    title1
    title11

author2:
    title2
    title22
    title222

我正在考虑创建一个 hashmap 映射作者 => 书籍列表,但是,正如我在 SO 中所读到的,hashmap 在 h:datatable,也不在 ui:repeat 中。

关于如何实现这一点的任何提示?

谢谢。

PS:我使用的是 jsf 1.2

欢迎提出更好的标题

【问题讨论】:

    标签: java jsf uirepeat


    【解决方案1】:

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

    我建议创建一个带有书籍列表的 Author 类:

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

    然后您可以基于List&lt;Author&gt; 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>
    

    【讨论】:

    • 谢谢,我就是这样做的。
    猜你喜欢
    • 2016-02-15
    • 1970-01-01
    • 2012-10-09
    • 2017-09-07
    • 2013-10-13
    • 2012-03-23
    • 1970-01-01
    • 1970-01-01
    • 2011-03-01
    相关资源
    最近更新 更多