I solve this my question with this code:
root = new DefaultTreeNode("root", null);
TreeNode projetNode = new DefaultTreeNode("node", new Document(projet), root);
for (Tache ta : taches) {
TreeNode tacheNode = new DefaultTreeNode("node", new Document(ta), projetNode);
for (Activite ac : activites) {
Tache tache = ac.getTache();
if (tache.getId() != ta.getId()) { continue;}
TreeNode activiteNode = new DefaultTreeNode("node", new Document(ac), tacheNode);
for (Phase ph : phases) {
Activite activite = ph.getActivite();
if (activite.getId() != ac.getId()) {continue;}
TreeNode phaseNode = new DefaultTreeNode("leaf", new Document(ph), activiteNode);
}
}
}
And I was write the Document constructor like this:
public class Document implements Serializable {
private static final long serialVersionUID = 1L;
private Projet projet;
private Tache tache;
private Activite activite;
private Phase phase;
private String nameProjet;
public Document(Object obj) {
if (obj instanceof Phase) {
phase = (Phase)obj;
}else if (obj instanceof Activite) {
activite = (Activite)obj;
}else if (obj instanceof Tache) {
tache = (Tache)obj;
}else{
projet = (Projet)obj;
}
}
//gets and sets
}
And to finish, the xhtml code to renderer each "objects" rows :
<p:treeTable id="treeTable" value="#{documentsController.root}"
var="document" selection="#{documentsController.selectedNode}" selectionMode="single" resizableColumns="true">
<f:facet name="header">
<h:outputText value="#{bundle.update} #{bundle.projet}" />
</f:facet>
<p:column>
<f:facet name="header">
<h:outputText value="#{bundle.name}" />
</f:facet>
<p:outputLabel value="#{document.projet.nomProjet}" rendered="#{document.projet == null}"/>
<p:outputLabel value="#{document.tache.nomTache}" renderer="#{document.tache == null}" />
<p:outputLabel value="#{document.activite.nomActivite}" rendered="#{document.activite == null}"/>
<p:outputLabel value="#{document.phase.nomPhase}" rendered="#{document.phase == null}"/>
</p:column>
</p:treeTable>