-
1. Re: Trying to get a tree to use xml elements to populate nod
meghiddo May 25, 2009 7:42 PM (in response to meghiddo)I solved that first problem so here is the next:
I followed the exact example from thsi site:
http://livedemo.exadel.com/richfaces-demo/richfaces/treeNodesAdaptor.jsf?tab=usage&cid=488771
It is the tree example for richfaces. However, when I try to dispaly it on my local host it just shows a blank white page. Which I assume means it is not finding any nodes to populate the tree with. if I understand the code, they are getting their nodes from /WEB-INF/src, because this is in the java code:package testContainer; public class FileSystemBean { private static String SRC_PATH = "/WEB-INF/src"; private FileSystemNode[] srcRoots; public synchronized FileSystemNode[] getSourceRoots() { if (srcRoots == null) { srcRoots = new FileSystemNode(SRC_PATH).getNodes(); } return srcRoots; } }
So I am assuming I need to replace WEB-INF/src with my own data source. I tried using an xml file that I put in the same folder as the tree.xhtnl page, so I replaced WEB-INF/src with /src.xml, but it is also showing just a white page. I feel like I am close to figuring this out, but I just need to figure out what should be put in there as the data source. Any suggestions? -
2. Re: Trying to get a tree to use xml elements to populate nod
meghiddo May 25, 2009 7:45 PM (in response to meghiddo)also, when I try to replace WEB-INF/src with other things sometimes instead of a blank page it gets an error saying:
javax.servlet.ServletException: /test/recursiveNodesTest/tree.xhtml @11,120 roots="#{fileSystemBean.sourceRoots}": Error reading 'sourceRoots' on type testContainer.FileSystemBean -
3. Re: Trying to get a tree to use xml elements to populate nod
meghiddo May 25, 2009 7:57 PM (in response to meghiddo)The more I mess with this the more I realize it is coming down to the exact same problem I have been trying to find an answer for for days now. I need to write the java code that will go through the xml elements and use the data from them to populate nodes. There is sample code out there for how to do this using a .properties file, and ow to do this usng modes, but I cant find any help anywhere for doing this from xml! Its getting really old, Im not sure what else to try, where else to ask for help, or how else to phrase the problem.
Maybe if someone see the source code for doing this using nodes or a .properties file..
Here is how to do it using nodes as yoru data source:private static String DATA_PATH = "/treeData/treeTest.properties"; private FileSystemNode[] srcRoots; public synchronized FileSystemNode[] getSourceRoots() { if (srcRoots == null) { srcRoots = new FileSystemNode(DATA_PATH).getNodes(); } return srcRoots; }
and using a .properties file as the data source:import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Properties; import javax.faces.FacesException; import javax.faces.component.UIComponent; import javax.faces.context.ExternalContext; import javax.faces.context.FacesContext; import org.richfaces.component.UITree; import org.richfaces.component.html.HtmlTree; import org.richfaces.event.NodeSelectedEvent; import org.richfaces.model.TreeNode; import org.richfaces.model.TreeNodeImpl; public class SimpleTreeBean { private TreeNode rootNode = null; private List<String> selectedNodeChildren = new ArrayList<String>(); private String nodeTitle; private static final String DATA_PATH = "/treeData/treeTest.properties"; //private static final String DATA_PATH = "http://webc-apps.ni.com/measure/1.01/projects"; private void addNodes(String path, TreeNode node, Properties properties) { boolean end = false; int counter = 1; while (!end) { String key = path != null ? path + '.' + counter : String.valueOf(counter); String value = properties.getProperty(key); if (value != null) { TreeNodeImpl nodeImpl = new TreeNodeImpl(); nodeImpl.setData(value); node.addChild(new Integer(counter), nodeImpl); addNodes(key, nodeImpl, properties); counter++; } else { end = true; } } } private void loadTree() { FacesContext facesContext = FacesContext.getCurrentInstance(); ExternalContext externalContext = facesContext.getExternalContext(); InputStream dataStream = externalContext.getResourceAsStream(DATA_PATH); //DeviceXMLAO data = new DeviceXMLAO(); //data.getClass(); try { Properties properties = new Properties(); properties.load(dataStream); rootNode = new TreeNodeImpl(); addNodes(null, rootNode, properties); } catch (IOException e) { throw new FacesException(e.getMessage(), e); } finally { if (dataStream != null) { try { dataStream.close(); } catch (IOException e) { externalContext.log(e.getMessage(), e); } } } } public void processSelection(NodeSelectedEvent event) { HtmlTree tree = (HtmlTree) event.getComponent(); nodeTitle = (String) tree.getRowData(); selectedNodeChildren.clear(); TreeNode currentNode = tree.getModelTreeNode(tree.getRowKey()); if (currentNode.isLeaf()){ selectedNodeChildren.add((String)currentNode.getData()); }else { Iterator<Map.Entry<Object, TreeNode>> it = currentNode.getChildren(); while (it!=null &&it.hasNext()) { Map.Entry<Object, TreeNode> entry = it.next(); selectedNodeChildren.add(entry.getValue().getData().toString()); } } } public TreeNode getTreeNode() { if (rootNode == null) { loadTree(); } return rootNode; } public String getNodeTitle() { return nodeTitle; } public void setNodeTitle(String nodeTitle) { this.nodeTitle = nodeTitle; } }
Now from seeing how it is done in these two ways, can someone set me down the right path for doing this from xml? -
4. Re: Trying to get a tree to use xml elements to populate nod
ilya_shaikovsky May 26, 2009 4:31 AM (in response to meghiddo)checkout http://anonsvn.jboss.org/repos/richfaces/branches/community/3.3.X/samples/tree-demo
here is the sample with xml present. instructions of how to works with our dev samples could be found at wiki. -
5. Re: Trying to get a tree to use xml elements to populate nod
meghiddo May 26, 2009 3:18 PM (in response to meghiddo)I thought that example uses a .properties file as the data source? I have been able to get that working just fine, but it isnt using an xml data source, unless I have missed something