How to display Parent and Child ( two different objects ) in treetable primefaces?

不问归期 提交于 2019-12-06 06:09:33

Your XHTML page is different form back bean. But in your case you can make another Class which have only those properties which is needs to be display. and use that class to be display on XHTML pages. lets us know if not work.

Solution:

ManagedBean tree getter:

private TreeNode tree;

public TreeNode getTree() {
    if (tree == null) {

        tree = new CheckboxTreeNode("root", null);

        for (UniversityDetail u : universityDetailList) {
            TreeNode uNode = new CheckboxTreeNode("university" ,u ,tree);
            for (CollegeDetail c : u.getCollegeDetail()) {
                TreeNode cNode = new CheckboxTreeNode("collage" ,c ,uNode);
            }
        }
    }

    return tree;

}

xhtml:

<p:treeTable value="#{ManagedBean.tree}" var="object" nodeVar="node" id="multiSelect"  
             selection="#{ManagedBean.selectedNodes}" selectionMode="checkbox">  

    <f:facet name="header">  
        College Dropdown  
    </f:facet>  

    <p:column> 

        <p:treeNode type="university" rendered="#{node.type == 'university'}">
            <h:outputText value="#{object.universityName}" />
        </p:treeNode>

        <p:treeNode type="college" rendered="#{node.type == 'college'}">
            <h:outputText value="#{object.collegeName}" />
        </p:treeNode>

    </p:column>  

    <p:column> 

        <p:treeNode type="university" rendered="#{node.type == 'university'}">
            <h:outputText value="#{object.universityId}" />
        </p:treeNode>

        <p:treeNode type="college" rendered="#{node.type == 'college'}">
            <h:outputText value="#{object.collegeId}" />
        </p:treeNode>

    </p:column>  

</p:treeTable>

Tip: use rendered atribute with node type:

rendered="#{node.type == 'university'}"
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!