TreeTable

UI Components for JSF
Post Reply
coco100
Posts: 1
Joined: 16 Nov 2017, 19:22

16 Nov 2017, 19:29

Hi,

I have a table in database like the below:

Code: Select all

 create table hc_wbs
(id number, parent_id number, code varchar2(50), name varchar2(120));
insert into hc_wbs
values(1, null, 'code1', 'code name');

insert into hc_wbs
values(2, 1, 'code2', 'code name 2');

insert into hc_wbs
values(3, 1, 'code3', 'code name 3');

insert into hc_wbs
values(4, 2, 'code4', 'code name4');

insert into hc_wbs
values(5, 2, 'code5', 'code name5');

insert into hc_wbs
values(6, 4, 'code6', 'code name6');
I would like to use it in a hierarchy?
Can someone teach me?


My trials are below

Code: Select all

@ManagedBean
@SessionScoped
public class TreeTableManagedBean {
    
    
    
    private TreeNode root = new DefaultTreeNode("Project", null);
    private TreeNode singleSelectedNode;
//    private TreeNode [] multipleSelectedNodes;
//    private TreeNode [] checkboxSelectedNodes;

    public TreeTableManagedBean() throws SQLException{
            // Populate Document Instances
          
            // Create Documents TreeNode
            TreeNode documents = new DefaultTreeNode(new Document("Project","0","Documents"), this.root);
            // Create Document TreeNode
            try(Connection conn = new DataBaseConnection().getDriver();
                Statement stmt = conn.createStatement();
                ResultSet rs = stmt.executeQuery("select id,   LPAD(' ', 2 * LEVEL - 1)||code , level l\n" +
                                            "from hc_wbs\n" +
                                            "start with parent_id is null\n" +
                                            "connect by prior id = parent_id");
                ){
                    while(rs.next()){
                         Document d = new Document( rs.getString(1), rs.getString(2), rs.getString(3));
                         TreeNode t = new DefaultTreeNode(d, documents);
                         Tree tr = new Tree();
                       
                    }
            }catch(Exception e){
                e.printStackTrace();
            }

    }
public void addNode(String name, String author, String id){
        Document d = new Document(name, id, author);
        TreeNode t = new DefaultTreeNode(d, singleSelectedNode);
    }
    
    public TreeNode getRoot() {
            return root;
    }

    public void setRoot(TreeNode root) {
           this.root = root;
           
    }

    public TreeNode getSingleSelectedNode() { 
       
            return singleSelectedNode;
    }

    public void setSingleSelectedNode(TreeNode singleSelectedNode) {
            this.singleSelectedNode = singleSelectedNode;
    }

}
but I have only the root as Hierarchy

A lot of thanks

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 45 guests