8 Replies Latest reply on May 31, 2009 2:09 PM by Matt Kohanek

    How to get my List<String> to bind to richfaces tree nodes?

    Matt Kohanek Novice

      I have code where I pull data from a web service, use xml to parse it, and then add the text nodes I want it to into a list. This all works as intended because when I print out the list it prints out the values I expect it to.
      But I have tried using this list to populate a tree and it just doesnt seem to work. I keep getting just a blank page. Im not sure if Im just doing the html wrong (thought Ive tried quite a few things) or if the tree node is calling the value of this lest before the operations are performed to populate the list.

      Here is my code to populate and get the list that contains the needed values:

      public class Nodes(){
      static List<String> ids = new ArrayList<String>();
      
      
       public static List<String> getIds() {
      
      
       XmlData nodes = new XmlData();
       DeviceCollectionXMLAO access = new DeviceCollectionXMLAO();
       HttpClientMethods method = new HttpClientMethods();
       DeviceCollection deviceCollection = null;
      
       try {
       deviceCollection = access.readXML(method.getResponseBodyAsStream(null));
       } catch (IOException e) {
       // TODO Auto-generated catch block
       e.printStackTrace();
       } catch (Exception e) {
       // TODO Auto-generated catch block
       e.printStackTrace();
       }
      
      
      
       for (Device device : deviceCollection.getDevices()){
       String x = device.getDeviceId();
       ids.add(x);
       }
      
       return ids;
      
       }
      
      
       public static void setIds(List<String> ids) {
       Temp.ids = ids;
       }
      }}


      So as you can see the values are getting stored in ids. Have I done something wrong here, or am I just binding this to the tree incorrectly?

      Here is how I tried to bind it to the tree btw:

      <ui:composition xmlns="http://www.w3.org/1999/xhtml"
       xmlns:ui="http://java.sun.com/jsf/facelets"
       xmlns:h="http://java.sun.com/jsf/html"
       xmlns:f="http://java.sun.com/jsf/core"
       xmlns:a4j="http://richfaces.org/a4j"
       xmlns:rich="http://richfaces.org/rich">
      
       <h:form>
      
       <rich:tree style="width:300px" switchType="ajax" >
       <rich:recursiveTreeNodesAdaptor nodes="#{nodesBean.ids}" />
       </rich:tree>
      
      
       </h:form>
      
      </ui:composition>