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.
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
Another option is to use ui:repeat
inside a column to get all the values of a 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>
...
Primefaces expandable rows should address your need, only you'll need to get creative with the child row component. You could use prime faces data list component as the child row component. It'll look something like:
<p:row expansion>
<p:datalist value ="#{yourTableRowVar.friendslist} Var="friend">
#{friend.firstName}
</p:datalist>
</p:row expansion>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With