1

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.

1 Answers1

0

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. :-)

Community
  • 1
  • 1
yem yem yen
  • 309
  • 2
  • 10
  • Unfortunately I'm new to JSF. Would you please show me a basic example how to do it? –  Nov 09 '12 at 12:11
  • I am sorry.. Did not see the comment earlier. Did you already find out how to put a command link - or you need help with HashMap? – yem yem yen Dec 16 '12 at 04:35