I am new in java and JSF and I have (IMHO) big problem. I want to list disk folder in Tree control, but I do not know how to do this.
I wrote somthing like below, but it's return just subfolders from parent. I do not know how to read sub...sub...folders. I could build new path and add to tree (or treeNode), but I do not know it is good idea, may be there is simple way.
Could someone show example code ?
Code: Select all
String realPath = "somePath";
File rootDir = new File(realPath);
TreeNode rootNode = new DefaultTreeNode("Root", null);
File[] subDirs = rootDir.listFiles(new FileFilter() {
@Override
public boolean accept(File rootDir) {
return rootDir.isDirectory();
}
});
for (int i = 0; i < subDirs.length; i++) {
if (!(subDirs[i].getName().toUpperCase().equals("META-INF")
|| subDirs[i].getName().toUpperCase().equals("WEB-INF"))) {
rootNode.addChild(new DefaultTreeNode(subDirs[i].getName(), null));
}
}