Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    XML not getting loaded in TreeGrid

    Hi,
    I have created a Multi Column Tree in my SmartGWT application. The first column will have XML and the rest of the columns will have basic data. But when I execute the application its hangs and I get some script error saying "Script is taking too long to run .... ". I still continued with the message but it kept coming back again everytime.

    My XML is not getting loaded in the Tree Grid.

    The following is the code snippet :

    Code:
    private TreeGrid getTreeGrid()
    {
    		TreeGrid treeGrid = new TreeGrid();
    		treeGrid.setCanEdit(true);  
    		treeGrid.setLoadDataOnDemand(false);  
    		treeGrid.setWidth(600);  
    		treeGrid.setHeight(300);  
    		treeGrid.setShowOpenIcons(false);  
    		treeGrid.setShowDropIcons(false);  
    		treeGrid.setClosedIconSuffix("");  
    		treeGrid.setAutoFetchData(true);
    		treeGrid.setShowConnectors(true);
    		TaskXmlDS taskXmlDS = TaskXmlDS.getInstance();
    		treeGrid.setDataSource(taskXmlDS);
    		
    		TreeGridField taskNameField = new TreeGridField("taskName");  
    		taskNameField.setFrozen(true);   
    		TreeGridField taskDescField = new TreeGridField("taskDesc");  
    		TreeGridField taskStartTimeField = new   TreeGridField("taskStartTime");  
    
    		TreeGridField taskEndTimeField = new TreeGridField("taskEndTime");  
               
    		treeGrid.setFields(taskNameField, taskDescField, taskStartTimeField,taskEndTimeField);  
            
            return treeGrid;	
    }
    Code:
    public class TaskXmlDS extends DataSource {
    
        private static TaskXmlDS instance = null;
    
        public static TaskXmlDS getInstance() {
            if (instance == null) {
                instance = new TaskXmlDS("employeesDS");
            }
            return instance;
        }
    
        public TaskXmlDS(String id) {
    		
    	    setID(id);
    	    setRecordXPath("/tasks/task");
    	    
    		DataSourceTextField taskNameField = new DataSourceTextField("taskName", "Task Name" , 128);
    		DataSourceTextField taskNameDesc = new DataSourceTextField("taskDesc", "Description", 100);
    		DataSourceTextField taskStartTime = new DataSourceTextField("taskStartTime", "Start Time", 80);
    		DataSourceTextField taskEndTIme = new DataSourceTextField("taskEndTime", "End Time", 80);
    
    		DataSourceIntegerField taskParentId = new DataSourceIntegerField("taskParentId", "Parent ID");
    		taskParentId.setPrimaryKey(true);
    		taskParentId.setRequired(true);
    
    		DataSourceIntegerField taskIdField = new DataSourceIntegerField("taskId", "Task ID");
    		taskIdField.setRequired(true);
    		taskIdField.setForeignKey(id + ".taskParentId");
    		taskIdField.setRootValue("0");
    		
    		setFields(taskNameField, taskNameDesc, taskStartTime, taskEndTIme);
    		setDataURL("tasks.data.xml");
    		setClientOnly(true);	
        }
    }
    The following is the XML:
    Code:
    <tasks>
    	<task>
    		<taskId>1</taskId>
    		<taskParentId>0</taskParentId>
    		<taskName>Parent Task Name</taskName>
    		<taskDesc>Parent Task Desc</taskDesc>
    		<taskStartTime>taskStartTime</taskStartTime>
    		<taskEndTime>taskendTime</taskEndTime>
    	</task>
    	
    	<task>
    		<taskId>2</taskId>
    		<taskParentId>1</taskParentId>
    		<taskName>Task 1</taskName>
    		<taskDesc>Task 1 Desc</taskDesc>
    		<taskStartTime>09-04-2009 10:00:00</taskStartTime>
    		<taskEndTime>09-04-2009 10:30:00</taskEndTime>
    	</task>
    	
    	<task>
    		<taskId>3</taskId>
    		<taskParentId>1</taskParentId>
    		<taskName>Task 3</taskName>
    		<taskDesc>Task 3 Desc</taskDesc>
    		<taskStartTime>09-04-2009 10:30:00</taskStartTime>
    		<taskEndTime>09-04-2009 10:45:00</taskEndTime>
    	</task>
    </tasks>
    Can you please help me out with this issue. I will really appreciate any sort of help. Thank you.

    #2
    Script error resolved but relationships not showing

    I managed to get out of the script error. Got the latest Smart GWT jar and it worked fine. But now the problem I am facing is that I am not getting the parent child relations in the tree. I see three different nodes without any relation between them. I am still using the same XML.

    Please help.

    Comment


      #3
      Your foreignKey is reversed. It should be declared on the taskParentId field, pointing to the taskId field.

      Comment


        #4
        It worked. Thanks a ton. :)

        Comment


          #5
          The result is :

          Code:
          public class TaskXmlDS extends DataSource {
          
              private static TaskXmlDS instance = null;
          
              public static TaskXmlDS getInstance() {
                  if (instance == null) {
                      instance = new TaskXmlDS("employeesDS");
                  }
                  return instance;
              }
          
              public TaskXmlDS(String id) {
          		
          	    setID(id);
          	    setRecordXPath("/tasks/task");
          	    
          		DataSourceTextField taskNameField = new DataSourceTextField("taskName", "Task Name" , 128);
          		DataSourceTextField taskNameDesc = new DataSourceTextField("taskDesc", "Description", 100);
          		DataSourceTextField taskStartTime = new DataSourceTextField("taskStartTime", "Start Time", 80);
          		DataSourceTextField taskEndTIme = new DataSourceTextField("taskEndTime", "End Time", 80);
          
          		DataSourceIntegerField taskParentId = new DataSourceIntegerField("taskParentId", "Parent ID");
          		taskParentId.setPrimaryKey(true);
          		taskParentId.setRequired(true);
          		taskParentId.setForeignKey(id + ".taskId");
          
          		DataSourceIntegerField taskIdField = new DataSourceIntegerField("taskId", "Task ID");
          		taskIdField.setRequired(true);
          //		taskIdField.setForeignKey(id + ".taskParentId");
          		taskIdField.setRootValue("0");
          		
          		setFields(taskIdField, taskParentId, taskNameField, taskNameDesc, taskStartTime, taskEndTIme);
          		setDataURL("tasks.data.xml");
          		setClientOnly(true);	
              }
          }
          Last edited by immobilia; 10 Apr 2009, 03:51.

          Comment

          Working...
          X