0

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

ccheneson
  • 49,072
  • 8
  • 63
  • 68

1 Answers1

2

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>
Matt Handy
  • 29,855
  • 2
  • 89
  • 112