views:

53

answers:

2

how to generate dynamic tree.properties file from database and pass it to tree structure of richfaces.

+1  A: 

look to my blog http://www.przemek-nowak.pl - richfaces tree component

przemek
+1  A: 

Nice Link 4 implementing Lucene(Hibernate Search) http://www.amin-mc.blogspot.com/

Using Example of przemek TreeManager.java

enter code : public class TreeManager implements Serializable{
@ManagedProperty(value="#{BuyerServiceBean}")
BuyerServiceBean buyerServiceBean;

public BuyerServiceBean getBuyerServiceBean() {
    return buyerServiceBean;
}

public void setBuyerServiceBean(BuyerServiceBean buyerServiceBean) {
    this.buyerServiceBean = buyerServiceBean;
}
private TreeNode<String> root = null;
private String nodeTitle;
private String selectedCategory;

public TreeManager() {}

public TreeNode getRoot() {
    if (root == null) {
        List<DepartmentMasterDataBean> c = new ArrayList<DepartmentMasterDataBean>();
        c = buyerServiceBean.treeList(0);
        TreeModel tm = null;
        tm = new TreeModel(c);
        root = tm.getRoot();
    }
    return root;
}

public void processSelection(NodeSelectedEvent event) {
    HtmlTree tree = (HtmlTree) event.getComponent();
    selectedCategory = (String)tree.getRowData();
    String test = tree.getRowKey().toString();
    Integer id = Integer.parseInt(test.substring(test.lastIndexOf(":")+1, test.length()));
    buyerServiceBean.getDepartmentMasterBindBean().setParentdeptid(id);
    setNodeTitle(selectedCategory);
}

public String getNodeTitle() {
    return nodeTitle;
}

public void setNodeTitle(String nodeTitle) {
    this.nodeTitle = nodeTitle;
}

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

public String getSelectedCategory() {
    return selectedCategory;
}

public void setSelectedCategory(String selectedCategory) {
    this.selectedCategory = selectedCategory;
}

}

TreeModel.java

enter code here : public class TreeModel {


private TreeNode<String> root;

public TreeModel(List<DepartmentMasterDataBean> c) {
    root = new TreeNodeImpl<String>();
    root.setParent(null);
    root.setData("Kategorie");
    createChildren(root, c);
}

private void createChildren(TreeNode<String> r, List<DepartmentMasterDataBean> ch) {
    for (DepartmentMasterDataBean c : ch) {
        TreeNode<String> nodeImpl = new TreeNodeImpl<String>();
        nodeImpl.setData(c.getDeptname());
        r.addChild(c.getDeptid(), nodeImpl);            
        if (c.getChildren() != null) {
            createChildren(nodeImpl, c.getChildren());
        }
    }
}

public TreeNode getRoot() {
    return root;
}

}

Important method for iteration

enter code here : public List<DepartmentMasterDataBean> treeList(Integer deptid) {
    List<DepartmentMasterDataBean> dataBeans = new ArrayList<DepartmentMasterDataBean>();
    List<DepartmentMaster> dms = departmentMasterService.getDepartmentList("parentdeptid", Operation_enum.EQ, deptid);
    for (DepartmentMaster departmentMaster : dms) {
        dataBeans.add(_toDepartmentMasterDataBean(departmentMaster));
    }
    return dataBeans;
}

public DepartmentMasterDataBean _toDepartmentMasterDataBean(DepartmentMaster departmentMaster) {
    DepartmentMasterDataBean dmdb = new DepartmentMasterDataBean();
    List<DepartmentMasterDataBean> list1 = new ArrayList<DepartmentMasterDataBean>();
    dmdb.setDeptid(departmentMaster.getDeptid());
    dmdb.setDeptname(departmentMaster.getDeptname());
    dmdb.setParentdeptid(departmentMaster.getParentdeptid());
    dmdb.setAddress(departmentMaster.getAddress());
    dmdb.setDatentime(departmentMaster.getDatentime());
    dmdb.setPhone(departmentMaster.getPhone());
    List<DepartmentMaster> dms = new ArrayList<DepartmentMaster>();
    dms = departmentMasterService.getDepartmentList("parentdeptid", Operation_enum.EQ, departmentMaster.getDeptid());
    for (DepartmentMaster departmentMaster1 : dms) {
        list1.add(_toDepartmentMasterDataBean(departmentMaster1));
    }
    dmdb.setChildren(list1);
    return dmdb;
}
taher