0

我一直在使用 Apache myfaces tomahawk tree2 组件在我的 jsf1.1 网页中渲染目录结构。在支持 bean 中,我编写了一个递归函数调用来初始化要在 tree2 组件中显示的文件夹名称和文档名称。

实例变量是:

private TreeNode treeData;
TreeNodeBase personNode=new TreeNodeBase();
TreeNodeBase folderNode;

在方法1中:

personNode = new TreeNodeBase("folder",value from the database, false);
personNode.getChildren().add(new TreeNodeBase("document", document name, true));

如果创建的文件夹有子文件夹,我会调用另一种方法来查找它的子文件夹以及它的文档。如果存在,则使用以下代码将文件夹添加到父文件夹。

在方法2中:

while(end of all folders list) {
folderNode = new TreeNodeBase("person", folder1, false);// add all folders
folderNode.getChildren().add(new TreeNodeBase("document", document name, true));//add document
personNode.getChildren().add(folderNode); //add sub folders to parent folder
}

绑定到组件的方法返回:

treeData.getChildren().add(personNode);
return treeData;

使用此代码,我最终将所有子文件夹添加到单个文件夹。因此,我需要获取父文件夹引用(或 ID)才能将其子文件夹添加到其中。

My question is: How to get the created folder id(or reference) with this line code or else suggest any other way of finding solution:

personNode = new TreeNodeBase("folder",value from the database, false);

Thank you:)

4

1 回答 1

0

To identify each new treenodebase() to reference(or use) later we could use method setIdentifier() of TreeNodeBase class. By that we can identify each node uniquely.

folderNode.setIdentifier(folder identification number);// where folderNode is TreeNodeBase Object and folder identification number can be any unique number for created node.
于 2013-10-18T11:02:59.003 回答