How to present embedded data in a Primfaces data file?

Here is my model:

User.java

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

I would like to create a friends user table like this:

users.jsf

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

Since there are many users, it is not possible to dump a user table at a time.

The dated data component is ideal in this case because it has built-in support for pagination. This is also ideal because you can sort the columns ...

Unfortunately, I could not find in Primefaces examples a way to change the range of rows in user columns.

How can I build this data table?

Some other OPs having this similar problem:

EDIT
Here is the final solution that I came up with .

+8
source share
5 answers

Based on @Kerem's answer, here is the solution I came up with:

To make nested datable as own strings of the main datatable, I redefined the CSS class .ui-dt-c . See the h:head style tag for more details.

 <?xml version="1.0" encoding="UTF-8"?> <html xmlns="http://www.w3c.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core" xmlns:p="http://primefaces.org/ui" xmlns:fn="http://java.sun.com/jsp/jstl/functions" xmlns:ui="http://java.sun.com/jsf/facelets"> <h:head> <title>USERS and their friends</title> <style> .ui-dt-c { padding: 0px !important; } </style> </h:head> <h:body> <h:form id="form"> <p:dataTable value="#{users.list}" var="u"> <p:columnGroup type="header"> <p:row> <p:column headerText="USER" /> <p:column headerText="FRIENDS" /> </p:row> </p:columnGroup> <p:column>#{u.name}</p:column> <p:column> <p:dataTable value="#{u.friends}" var="f"> <p:column>#{f.name}</p:column> </p:dataTable> </p:column> </p:dataTable> </h:form> 
0
source

Just use a different data table inside the 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

+14
source

Another option is to use ui:repeat inside the column to get all the values ​​of the collection.

Example:

 <p:dataTable var="user" value="#{userGroupBacking.users}" id="userTable"> <p:column headerText="User"> <h:outputText value="#{user.name}" /> </p:column> <p:column headerText="Groups"> <ui:repeat var="group" value="#{user.groups}"> <h:outputText value="#{group.name}" /><br /> </ui:repeat> ... 
+3
source

Expandable line charts should take into account your needs, only you will need to create an ad with a child line component. You can use the primary faces of the data list components as a component of the child row. It will look something like this:

  <p:row expansion> <p:datalist value ="#{yourTableRowVar.friendslist} Var="friend"> #{friend.firstName} </p:datalist> </p:row expansion> 
+2
source

There are two solutions for me:

1- If I want to browse a user by user and get a list of friends, in this case I prefer dataList .

 <p:dataTable value="#{users.list}" var="u"> <p:column headerText="USER">#{u.name}</p:column> <p:column headerText="FRIENDS"> <p:dataList value="#{u.friends}" var="f"> #{f.name} </p:dataTable> </p:column> </p:dataTable> 

2- In the case where I can directly access the list of friends (listFreinds [username, friend]) or when I use the JPQL query :

 <p:dataTable value="#{users.listFreinds}" var="u" sortBy="#{u.userName}"> <p:column headerText="USER" groupRow="true">#{u.userName}</p:column> <p:column headerText="FRIENDS">#{u.friend}</p:column> </p:dataTable> 

The second case is a new proprietary solution with String Grouping , since v6.0.11

https://www.primefaces.org/showcase/ui/data/datatable/rowGroup.xhtml

+1
source

All Articles