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

标签 java primefaces treetable

我在 TreeTable 的同一列中添加许多对象类型时遇到问题。创建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);
          }
       }
    }

之后,我尝试调用 Treetable 中的对象,它可以工作,但是当我尝试在列中添加这些对象时,它不起作用。部分代码如下:

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

问题是在“名称”列上列出与层次结构节点相关的对象名称。

有人知道我该怎么做吗?

很高兴得到您的关注。

谢谢!

最佳答案

我用这段代码解决了我的问题:

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);
                }
            }
        }

我是这样编写文档构造函数的:

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
}

最后,渲染每个“对象”行的 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>

关于java - 在 TreeTable 的同一列中添加许多对象类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17041458/

相关文章:

html - PrimeFaces:格式化 <div 样式 ="float:right;"> 导致命令按钮不起作用?

java.lang.Exception : No Function Found on type: org. primefaces.util.ComponentUtils with signature : java. lang.String resolveWidgetVar(java.lang.String)

jquery - 如何使用treeTable的显示功能?

java - 类型不匹配无法从 Boolean 转换为 Int(自定义方法中的数组)

Java : add some text in a video?

java - 以智能方式减少文本长度以适合单元格宽度

java - 如何更改maven的java路径

jsf-2 - Primefaces 对话框 + 命令按钮

javascript - 在 Javascript 中创建可排序的树/网格