Announcement

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

    Tree Load JSON not working (bug?)

    Hi everyone

    I have tried to do the same as the sample says but using JSON instead of XML

    http://www.smartclient.com/index.jsp...WT#treeLoadXML

    When i do it using XML, it works perfectly, but it only loads first childs when i use JSON.

    Here is the XML:
    Code:
     
    <response>
    	<errors />
    	<data>
    		<project>
    			<id>3</id>
    			<name>Checho Project</name>
    			<sprints>
    				<project>
    					<id>4</id>
    					<name>Backlog</name>
    				</project>
    			</sprints>
    		</project>
    	</data>
    </response>
    And here is the JSON:
    Code:
     
    {"response":
       {"errors":"","data":
             {"project":[{"id":1,"name":"Bee Project","sprints":
                                                         {"project":[{"id":3,"name":"sprint3"},{"id":4,"name":"sprint2"},{"id":2,"name":"sprint1"}]}},
                            {"id":5,"name":"Checho Project","sprints":
                                                          {"project":{"id":6,"name":"Backlog"}}}]
             }
       }
    }

    Code:
    	private ProjectDS(String id) {
    
    		setID(id);
    		setRecordXPath("/response/data/*");
    		// setRecordXPath("/Employees/*");
    		// DataSourceTextField nameField = new DataSourceTextField("Name", "Name", 128);
    		//
    		// DataSourceIntegerField employeeIdField = new DataSourceIntegerField("EmployeeId", "Employee ID");
    		// employeeIdField.setPrimaryKey(true);
    		// employeeIdField.setRequired(true);
    
    		DataSourceTextField idField = new DataSourceTextField("id", "Id", 128, true);
    		idField.setHidden(true);
    		idField.setPrimaryKey(true);
    
    		DataSourceTextField itemNameField = new DataSourceTextField("name", "Item", 128, true);
    
    		DataSourceField reportsToField = new DataSourceField();
    		reportsToField.setName("sprints");
    		reportsToField.setChildrenProperty(true);
    
    		setFields(idField, itemNameField, reportsToField);
    
    		setDataFormat(DSDataFormat.JSON);
    		setDataURL("bee_gui/sc/ds.xml");
    		setClientOnly(true);
    
    
    
    	}
    Did anyone deal with this?

    Thanks!
    Last edited by fedegaule; 8 Jul 2011, 10:39.

    #2
    Why is there no response to this question?

    A working JSON example would be nice, with full source disclosure. Your examples in the showcase show JSON implementations, but hide the JSON data driving the application, making it quite difficult to learn.


    For example: http://www.smartclient.com/#treesEditing
    Great, it looks wonderful, works well, and has the JS to run it. But where is the damn XML file? You provided JS source, XML Datasource structure. But no data. We are missing a key ingredient to understand how this system works, and I for one could really use a response to this question presented above. Though I am using smartclient not gwt, the resolution should be quite identical.



    I've scoured the documentation for a full 24 hours trying to locate an example or a reference to how to make this work. Not to mention the google searches, ooohhh my the many google searches...
    The only thing I can come up with after this deliberation, I found by using Firebug to "nab" your little RPC trickery in the showcase, which contacts via xhttprequest and pulls a SINGLE structure set, with a bunch of parameters.

    Meaning that fetchData only pulls a single structure of JSON at a time!? Meaning, you either need like 500 seperate JSON files, or you have to write a PHP "feeder" to dynamically provide single structures of JSON.
    The documentation said that it is the "norm" : loadondemand as you adequately named it. But doesnt that defeat the purpose of JSON? I mean I might as well just set clientOnly:true and use php to drop the whole damn thing in there.

    Can someone please help? The lack of json examples is nearly horrific.


    The following is what I am working with:
    Code:
    <script type="text/javascript">
    	
    	
    	
    
    	var restURL="interpreter.php";
    	isc.DataSource.create({
    		ID: "systemData",
    		dataURL: restURL+"?type=json&rsrc=systemTree",
    		dataFormat: "json",
    		dataProtocol: "getMessage",
    		clientOnly: false,
    		fields:[
    			{title:"Title", name:"title"},
    			{title:"Short Description", name:"descShort"},
    			{title:"Long Description", name:"descLong"},
    			{title:"Comments", name:"comments"},
    		],
    		autoFetchData: true
    	});
    
    	isc.VLayout.create({
    		position: "relative", // don't judge! :P
    		align: "left",
    		overflow: "visible",
    		members: [
    			
    // all right here it is...
    			isc.SearchForm.create({
    				width: 200,
    				height: 30,
    				fields:[
    					{editorType: "pickTree", 
    						showTitle: false, 
    						canSelectParentItems: true,
    						dataSource: "systemData", 
    						displayField: "title", 
    						valueField: "id",
    						change: "systemGrid.fetchData({title:value})" // is that wrong?
    					}
    				]
    			}),
    
    			
    			isc.ListGrid.create({
    				ID: "systemGrid",
    				dataSource: "systemData",
    				autoFetchData: false,
    				canEdit: true,
    				width: 900,
    				height: 600,
    				fields: [
    					{name: "title"},
    					{name: "Short Descrption"},
    					{name: "Comments"}
    				]
    			})
    		]
    	});
    		
    </script>
    and the json file loaded from php:
    Code:
    
    [
    	{
    		id: 1,
    		title: "Systems",
    		descShort: "A short description",
    		descLong: "A long description",
    		comments: "some comments",
    		child: [
    			{
    				id: 12,
    				title: "Poof I dont exist because smartclient dropped me?",
    				descShort: "A short description",
    				descLong: "A long description",
    				comments: "some comments"
    			}
    		]
    	},
    	{
    		id: 2,
    		title: "Tacos",
    		descShort: "A short description",
    		descLong: "A long description",
    		comments: "some comments"
    	
    	},
    ]
    Last edited by meowmix; 4 Aug 2011, 14:21.

    Comment


      #3
      Sounds like you haven't read the QuickStart Guide, since you don't seem to recognize a DataSource, and are unaware of the RPC tab in the Developer Console, which can show you the results of any request. See also the Tree Databinding Overview, and be sure to look at referenced properties such as loadDataOnDemand.

      Comment


        #4
        Thank you for the response Isomorphic. Actually I have read the quick start guide, front to back actually - first thing I did. Though it took a few hours to complete it was quite helpful and worth the effort.

        Though this question originated as a smartGWT problem -- in my regard I am working with SmartClient (javascript). I apologize for the confusion in that regard. But the problem the original poster above had, is my exact problem as well. And the resolution should be exactly the same, with slight alterations to syntax and design flow.

        JSON and children structures. There are literally no examples of this anywhere. Single structure example of json request does exist. However the only one that works with a large tree of json structures, appears to be fully hidden from view. THe link I provided in previous post is what im referring to: http://www.smartclient.com/#treesEditing . That is what my above posted code is based from, altered to support my php interpreter for smartclient.
        Works great, sends the json there. But since the treesEditing example does not provide the original data (which in fact happens to be json), I simply cannot figure out how it is supposed to work.

        That is to say, What is going on in the background that you've cleverly designed but hidden from view:
        Code:
        http://www.smartclient.com/isomorphic/IDACall?isc_rpc=1&isc_v=8.1-www-2011-08-03&isc_xhr=1&isc_tnum=4&_transaction=%3Ctransaction%20xmlns%3Axsi%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2F10%2FXMLSchema-instance%22%20xsi%3Atype%3D%22xsd%3AObject%22%3E%3CtransactionNum%20xsi%3Atype%3D%22xsd%3Along%22%3E4%3C%2FtransactionNum%3E%3Coperations%20xsi%3Atype%3D%22xsd%3AList%22%3E%3Celem%20xsi%3Atype%3D%22xsd%3AObject%22%3E%3Ccriteria%20xsi%3Atype%3D%22xsd%3AObject%22%3E%3CReportsTo%20xsi%3Atype%3D%22xsd%3Along%22%3E4%3C%2FReportsTo%3E%3C%2Fcriteria%3E%3CoperationConfig%20xsi%3Atype%3D%22xsd%3AObject%22%3E%3CdataSource%3Eemployees%3C%2FdataSource%3E%3CoperationType%3Efetch%3C%2FoperationType%3E%3C%2FoperationConfig%3E%3CappID%3EbuiltinApplication%3C%2FappID%3E%3Coperation%3Eemployees_fetch%3C%2Foperation%3E%3ColdValues%20xsi%3Atype%3D%22xsd%3AObject%22%3E%3CReportsTo%20xsi%3Atype%3D%22xsd%3Along%22%3E4%3C%2FReportsTo%3E%3C%2FoldValues%3E%3C%2Felem%3E%3C%2Foperations%3E%3C%2Ftransaction%3E&protocolVersion=1.0
        Date: Thu, 04 Aug 2011 22:30:03 GMT
        Server: Apache-Coyote/1.1
        X-Included-Test2: true
        X-Included-Test: true
        Cache-Control: no-cache
        Pragma: no-cache
        Expires: Thu, 04 Aug 2011 22:30:03 GMT
        Content-Encoding: gzip
        Content-Type: text/plain;charset=UTF-8
        Content-Length: 637
        Last edited by meowmix; 4 Aug 2011, 14:31.

        Comment


          #5
          And the Tree Databinding overview? It's linked everywhere in the Tree APIs because it's very important to read it. You haven't even tried to define a childrenProperty, so it seems clear you've been ignoring this key piece of doc. You confusion seems to come from this, rather than a lack of a sample for this particular combination of properties.

          Comment


            #6
            http://www.smartclient.com/docs/6.0/a/b/c/go.html
            I did actually , and followed every link on that page; perhaps I should screenshot my browser history as proof.
            Clearly I do not understand the point it is making, and so I will read it all again until I figure it out.

            I appreciate your lack of direct support, reminding me that I will have to work harder. Is difficult at times when you have deadlines, im sure you know about all that. After all, this is quite a complex system. Thanks anyways
            Last edited by meowmix; 4 Aug 2011, 14:41.

            Comment


              #7
              That's just a link to the top-level docs, not a specific item. But more importantly, you may have been reading ~5 year old docs (version 6.0 is past end of life).

              Comment


                #8
                aha! And there is my problem, surely that was the cause. Thanks alot

                Comment


                  #9
                  All right so the real problem I'm having is that I need to specify: idField, primaryKey, and Tree.parentIdField. --- via json somehow. Perhaps it's as simple as just writing it.. id: 1, pid: 0 in json, and those 3 parameters in the datasource definition. The second problem was that the DSRequest via GET that is being sent appears to be empty in terms of $_GET in php, and so I've been attaching my own parameters to it. I'll continue to do that since it is unclear to me why DSRequest does not attach parameters;
                  ie: "the client automatically sends a DSRequest to the server to ask for all immediate children of that node" does not appear to be factual in my case, in terms of what is being requested. It seems to be quite empty. So something is poorly configured on my end.

                  I'll play around with this and report back my findings. I appreciate your attention to detail , and time spent helping someone who has not properly read the documentation.
                  Last edited by meowmix; 4 Aug 2011, 15:06.

                  Comment


                    #10
                    Uhh close. There's two styles, load on demand (which works as you describe, and has a sample called Parent Linking) and one-shot loading. One-shot loading means you deliver the whole tree structure as nested JSON objects just like the format you pass to isc.Tree.create() if you're creating one (see Children Arrays sample). In this case you do not need unique ids, but if you are naming your arrays of children something other than the default "children", then you need to declare a field as being the childrenProperty.

                    Comment


                      #11
                      Just to finalize and inform of resolution, by re-reading https://www.isomorphic.com/smartgwt/...ataSource.html with particular attention to Hierarchical (Tree) data
                      I found that I had ALOT of problems.
                      - Lacked conceptual understanding of parentID "linked" lists for tree grids.
                      - lacked conceptual understanding of php back end used for LoadOnDemand requests
                      - Was not properly assigning primaryKey in datasource, nor parentID idiom.
                      - Finally: The isc.DataSource should have been isc.RestDataSource == reason why no data was attached to GET request. duh.. >.<

                      Amazing what one can do by taking the time to thoroughly read what was made available, and not skim over areas. Thanks again isomorphic. I'll refrain from wasting your time in the future.
                      Last edited by meowmix; 4 Aug 2011, 15:55.

                      Comment

                      Working...
                      X