Question

I have a problem to add many objects types in the same column in TreeTable. The method to create the TreeNodes is in below:

TreeNode taskProject = new DefaultTreeNode("node",projet,root);
for (Tache ta : listTache) {
     tache = ta;
     TreeNode taskNode = new DefaultTreeNode("node", tache, taskProject);   

     for (Activite ac : listActivite) {
        activite = ac;
        Tache tac = ac.getTache();
        if (tac.getId() != ta.getId()) {continue;}
        TreeNode taskActivite = new DefaultTreeNode("node",activite,taskNode);
          for (Phase ph : listPhases){
               phase = ph;
              Activite act = ph.getActivite();
              if (act.getId() != ac.getId()) {continue;}
              TreeNode taskPhase = new DefaultTreeNode("leaf",phase,taskActivite);
          }
       }
    }

After that, I tried to call the The object in the Treetable and it's work, but don't work when I tried to add these objects in the column. The part of code is in below:

<p:treeTable id="treeTable" liveResize="true"
    value="#{projetMediatorController.root}" var="projetMediator">
    <f:facet name="header">
        <h:outputText value="#{bundle.projet}" />
    </f:facet>

    <!-- column for the task/activities/phases -->
    <p:column>
        <f:facet name="header">
            <h:outputText value="#{bundle.name}" />
        </f:facet>
        <!-- problem -->
        <h:outputText value="#{projetMediatorController.projet.nomProjet}" />
        <!-- <h:outputText value="#{projetMediatorController.tache.nomTache}"/> -->
        <!--<h:outputText value="#{projetMediatorController.activite.nomActivite}"/>-->
        <!--<h:outputText value="#{projetMediatorController.phase.phase}"/>-->
    </p:column>
</p:treeTable>

And the problem is to list the objects names on the column "Name" respecting the hierarchy's nodes.

Someone know how can I do that ?

I'm glad for your attention.

Thank you!

Was it helpful?

Solution

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>

OTHER TIPS

You dont need to construct special class wrapper for node data objects. Use your class instances directly in TreeNode instead of Document object. In xhtml use rendered attribute on <p:treeNode> elements.

simmilar thread with this solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top