Topic
  • 3 replies
  • Latest Post - ‏2013-09-24T13:49:01Z by Conornei
dojouser
dojouser
5 Posts

Pinned topic Lazy loading in dojo

‏2013-09-18T03:53:26Z |

Hi All,

Can someone explain me with an example how can I implement the lazy loading in dijit tree  in RAD tool ? On query it should fetch the child nodes through REST calls.

 

Thanks and regards

Deb

  • Conornei
    Conornei
    6 Posts

    Re: Lazy loading in dojo

    ‏2013-09-24T09:09:36Z  

    There's a tutorial here on how to implement a Lazy loading tree:
    http://dojotoolkit.org/documentation/tutorials/1.8/store_driven_tree/

    If your using RAD then you probably will use JAXRS library for the REST service.

    You can do the javascript code in RAD as well & you can get type-ahead for the dojo functions if you add a dojo nature to the project with your javascript code.

    For the lazy loading to work when you get the root id (the root node of the tree e.g. /root) Then your rest service returns the json with the format

    {
        "name": "Root",
        "id": "root",
        "children": [{
             "name": "Congress",
             "id": "congress",
             "children": true
        }]

    }

    when you click the + on the UI for Congress node it will send a call to /congress, then your REST service should return

    {
        "name": "Root",
        "id": "root",
        "children": [{
             "name": "Congress",
             "id": "congress",
             "children": [{
                   "name": "Senator Kelly",
                   "id": "s0"
             }]
        }]

    }

     

    Updated on 2013-09-24T09:18:32Z at 2013-09-24T09:18:32Z by Conornei
  • dojouser
    dojouser
    5 Posts

    Re: Lazy loading in dojo

    ‏2013-09-24T13:14:40Z  
    • Conornei
    • ‏2013-09-24T09:09:36Z

    There's a tutorial here on how to implement a Lazy loading tree:
    http://dojotoolkit.org/documentation/tutorials/1.8/store_driven_tree/

    If your using RAD then you probably will use JAXRS library for the REST service.

    You can do the javascript code in RAD as well & you can get type-ahead for the dojo functions if you add a dojo nature to the project with your javascript code.

    For the lazy loading to work when you get the root id (the root node of the tree e.g. /root) Then your rest service returns the json with the format

    {
        "name": "Root",
        "id": "root",
        "children": [{
             "name": "Congress",
             "id": "congress",
             "children": true
        }]

    }

    when you click the + on the UI for Congress node it will send a call to /congress, then your REST service should return

    {
        "name": "Root",
        "id": "root",
        "children": [{
             "name": "Congress",
             "id": "congress",
             "children": [{
                   "name": "Senator Kelly",
                   "id": "s0"
             }]
        }]

    }

     

    Hi Conornei

    Thank you for the reply. I got another example which i wanted to implement to have better visualization but it is not working :( .

    http://download.dojotoolkit.org/release-1.4.0/dojo-release-1.4.0/dijit/tests/Tree_with_JRS.html

    Right Click-->View Page Source to see the underlying code in html page

     

    When I try this example I don't get any output in preview of RAD. I have included all the required .js and .css files in the JSP page with qualified links as well but while executing it on RAD no result is coming. Can you please let me know where I am going wrong in the above example?

    Also can you please suggest the values I need to pass in the below bold section as may be the code isnt identifying theas /tree may not be getting resolved to fetch the data.

    
    
    target:"tree/". Is there any other qualified links to provide the memory store data which we can pass here? 
    
    if you can try and see if you
    
    are getting the same error message of null screen. 
    

    Problematic section:

    <code>

    
    var d = new doh.Deferred;
    myStore = new dojox.data.JsonRestStore({
    target:"tree/", labelAttribute:"name"});
    doh.t(myStore, "store created");
    
    </code>
    
  • Conornei
    Conornei
    6 Posts

    Re: Lazy loading in dojo

    ‏2013-09-24T13:49:01Z  
    • dojouser
    • ‏2013-09-24T13:14:40Z

    Hi Conornei

    Thank you for the reply. I got another example which i wanted to implement to have better visualization but it is not working :( .

    http://download.dojotoolkit.org/release-1.4.0/dojo-release-1.4.0/dijit/tests/Tree_with_JRS.html

    Right Click-->View Page Source to see the underlying code in html page

     

    When I try this example I don't get any output in preview of RAD. I have included all the required .js and .css files in the JSP page with qualified links as well but while executing it on RAD no result is coming. Can you please let me know where I am going wrong in the above example?

    Also can you please suggest the values I need to pass in the below bold section as may be the code isnt identifying theas /tree may not be getting resolved to fetch the data.

    <pre dir="ltr" id="line1"> target:"tree/". Is there any other qualified links to provide the memory store data which we can pass here? if you can try and see if you are getting the same error message of null screen. </pre>

    Problematic section:

    <code>

    <pre dir="ltr" id="line1"> var d = new doh.Deferred; myStore = new dojox.data.JsonRestStore({ target:"tree/", labelAttribute:"name"}); doh.t(myStore, "store created"); </code> </pre>

    What version of dojo are you using and what version of Portal? The example I gave was for lazy loaded tree backed by a dojo.store.JsonRest (I think it came in in 1.7, older versions used dojo.data.JsonRestStore).

    If you can I'd avoid using the that JsonRestStore, I tried to get it working with that, but it's just more complicated than the new API. Better off trying the example I linked. Here's the demo for that page, easier to understand I think:
     

    http://dojotoolkit.org/documentation/tutorials/1.8/store_driven_tree/demo/lazy.php

    The target property is the string url to the REST service function, includeing the context root, e.g. "/contextroot/rest/route". You'd have this string mapped in a JAXRS Rest Class, that would have a method with the "/route" mapping & you'd figure out there what JSON object to return. Have a read through of the tutorial, it's actually explained farily well. The docs are pretty good for it as well.

    In the example I gave you don't need a memory store, you can use the JsonRest for that.

    For the null screen stuff, I can't help you with that, I don't use the preview in RAD for previewing the widgets, I just run it on the Portal Server when I want to test how things look.