tags:

views:

45

answers:

3

I have a test jsp with:

<head>
    <script src="http://ajax.googleapis.com/ajax/libs/dojo/1.5/dojo/dojo.xd.js" type="text/javascript">
</script>

<script type="text/javascript"> 
dojo.require("dojo.widget.Tree"); 
dojo.require("dojo.widget.TreeSelector"); 
dojo.require("dojo.widget.TreeNode"); 
dojo.require("dojo.widget.TreeContextMenu"); 
</script> 
</head>

<body>
<div dojoType="TreeSelector" widgetId="treeSelector"></div> 
<div dojoType="Tree" widgetId="treeWidget" selector="treeSelector"toggler="wipe"> 
<div dojoType="TreeNode" widgetId="1" title="First node" isFolder="false"></div> 
<div dojoType="TreeNode" widgetId="2" title="Second node"> 
    <div dojoType="TreeNode" widgetId="2.1" title="Second node First Child"></div> 
    <div dojoType="TreeNode" widgetId="2.2" title="Second node Second Child"></div> 
</div> 
<div dojoType="TreeNode" widgetId="3" title="Third node" isFolder="false"></div> 
</div>

This will not work in any browser. I thought this would be easy, it seems the dojo library is not being downloaded/found? Do I need to do anything else?

Also, my IDE, JDeveloper, reports that the attribute "dojoType" is not defined on element div.

+1  A: 

I'm not sure what the default behavior is when it's not present, but you probably need to define a djConfig with parseOnLoad set to true (or call the parser directly). See the following links for more information:

http://docs.dojocampus.org/djConfig

http://dojocampus.org/content/2008/03/08/the-dojo-parser/

Michael Morton
adding the djConfig attribute did not solve the issue. The example I took from the internet did not have djConfig as an element either
bmw0128
@bmw012: what about [using the google loader and deferring execution](http://stackoverflow.com/questions/3945147/newbie-dojo-google-cdn-question/3957759#3957759) ? Does that solve your issue?
haylem
+1  A: 

I have to say, this example looks like it is taken from a very old version of dojo, but you're trying to run it against Dojo 1.5. That most likely won't work. dojo.widget hasn't existed since...0.4, 0.9 maybe.

You may be right in your comment to the previous answer in that no parseOnLoad: true was necessary in the original example, but I'd also assure you that that example was not running any version of Dojo anywhere near what you're running it with.

Based on what you're looking at there, you may want to start somewhere like here: http://www.dojotoolkit.org/reference-guide/dijit/Tree.html

Ken
A: 

Follow the:

You need to:

  • register for an API key (or use a direct link as you did),
  • if not using a direct link but google.load, you need to defer the execution of your code using an onload callback.

Personally, I would just do something like:

within the <head> section of my.html:

<script type="text/javascript" src="http://www.google.com/jsapi?key=MY_API_KEY_GOES_HERE"&gt;&lt;/script&gt;
<script type="text/javascript" src="my.js"></script>

in my.js:

google.load("dojo", "1.5", {
  uncompressed: true
});

function OnLoad() {
  /* do stuff here */
}

google.setOnLoadCallback(OnLoad);
haylem
While I guess you *can* do this, none of this is required just to use Dojo off the Google CDN as the OP is doing (and as Dojo's website instructs you to do). No signup is necessary just to script src a dojo version directly off the CDN...
Ken
@Ken: I was giving an alternative to the OP to load libraries using the CDN. I suspect that if Google requires an API key to use the google loader, they probably plan on limiting the charge (according to the documentation, you should pass the key as well while using a direct URL, though I agree that it works without it for now - and for local URLs for testing). Now for the **rest** of my answer, it's relevant as the OP's not waiting for the Dojo code to be present and will need either way to defer its use. If not by using google.setOnloadcallback, then by using a normal onload callback.
haylem