开发者

Table header taken from the list item used with ui:repeat

Let's say I have the following class Book

class Book{
    String author;
    String title;
}

I retrieve a list of Book ( List<Book> ) and I want to display it in a table like

author1:
    title1
    title11

author2:
    title2
    title22
    title222

I was thinking to create 开发者_运维知识库a hashmap mapping author => list of books but , as I have read in SO, hashmap is not supported in h:datatable, nor in ui:repeat.

Any tips on how to achieve this?

Thank you.

PS: I am using jsf 1.2

Feel free to suggest a better title


I think you have to adapt your data model in order to get it into a h:dataTable.

I suggest to create a class Author with a list of books:

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

Then you can build a nested dataTable based on a List<Author> authorList (not tested):

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜