简体   繁体   English

在TreeTable的同一列中添加许多对象类型

[英]Add many objects types in the same column at TreeTable

I have a problem to add many objects types in the same column in TreeTable. 我有一个问题是在TreeTable的同一列中添加许多对象类型。 The method to create the TreeNodes is in below: 创建TreeNodes的方法如下:

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. 之后,我尝试调用Treetable中的对象并且它正常工作,但是当我尝试在列中添加这些对象时不起作用。 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! 谢谢!

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: 我是这样编写Document构造函数的:

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 : 并完成,xhtml代码渲染每个“对象”行:

<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>

You dont need to construct special class wrapper for node data objects. 您不需要为节点数据对象构造特殊的类包装器。 Use your class instances directly in TreeNode instead of Document object. 直接在TreeNode中使用您的类实例而不是Document对象。 In xhtml use rendered attribute on <p:treeNode> elements. 在xhtml中使用<p:treeNode>元素上的呈现属性。

simmilar thread with this solution simmilar线程与此解决方案

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM