简体   繁体   中英

Implement Java hashmap into Tree View

I'm new to JSF programing. I want to implement tree view example from the Primefaces website.

JSF page

<h:form id="form">  

    <p:tree value="#{TreeViewController.root}" var="node" dynamic="true" cache="true" id="tree" animate="true">  
        <p:treeNode>  
            <h:outputText value="Node"/>  
        </p:treeNode>  
    </p:tree>  

</h:form> 

Managed bean

private TreeNode root;  

    public TreeView() {  
        root = new DefaultTreeNode("Root", null);  
        TreeNode node0 = new DefaultTreeNode("Node 0", root);  
        TreeNode node1 = new DefaultTreeNode("Node 1", root);  
        TreeNode node2 = new DefaultTreeNode("Node 2", root);  

        TreeNode node00 = new DefaultTreeNode("Node 0.0", node0);  
        TreeNode node01 = new DefaultTreeNode("Node 0.1", node0);  

        TreeNode node10 = new DefaultTreeNode("Node 1.0", node1);  
        TreeNode node11 = new DefaultTreeNode("Node 1.1", node1);  

        TreeNode node000 = new DefaultTreeNode("Node 0.0.0", node00);  
        TreeNode node001 = new DefaultTreeNode("Node 0.0.1", node00);  
        TreeNode node010 = new DefaultTreeNode("Node 0.1.0", node01);  

        TreeNode node100 = new DefaultTreeNode("Node 1.0.0", node10);  
    }  

    public TreeNode getRoot() {  
        return root;  
    }  

I want to ask you these two questions: How I can open a new page when I click on a node? How I can display a Java hashmap into the tree as sub node of a node? For example I want to populate tree view with Java hashmap or Java map.

How I can open a new page when I click on a node?

In the example you linked to, an output text is created for every tree node, did you try putting one of their button elements there? Maybe command link ? And then configure it to open in a new window

How I can display a Java hashmap into the tree as sub node of a node? For example I want to populate tree view with Java hashmap or Java map.

If I understand correctly, you want to load the nodes using values from a HashMap. That would mean using an iterator and creating a node for each iteration in the managed bean. Plus putting in your logic to make the tree structure and links.

Oh and Thank you for introducing me to Primefaces. :-)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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