Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
407 views
in Technique[技术] by (71.8m points)

java - How to represent nested data in a Primefaces datatable?

Here is my model :

User.java

public class User {
   //...

   public List<User> getFriends() {
      // ...
   }
}

I would like to build a table of user friends like this :

users.jsf

+----------+------------+
|   USER   |   FRIENDS  |
+----------+------------+
|          |    ALICE   |
|          +------------+        
|   ADAM   |    BOB     |
|          +------------+
|          |    PITT    |
+----------+------------+
|          |            |
....

Since there are many users, it's not possible to dump the user table in one go.

The datatable component is ideal in this case because it has built-in pagination support. It is ideal too because it's possible to sort columns...

Unfortunately, I wasn't able to find through the Primefaces examples a way for changing the rowspan in user columns.

How can I build this datatable ?

Some other OP having this similar issue:

EDIT
Here is the final solution I came up with.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Just use another data table inside your column :)

<h:column>
    <h:dataTable var="friend" value="#{user.friends}">
        <h:column>
            <h:outputText value="#{friend.name}"/>
        </h:column>
    </h:dataTable>
</h:column>

This is how it looks on my localhost

enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...