I am trying to add a dojo widget to a page. Because it is an old application, I’m using dojo 1.6. The widget is defined in a js file with an HTML template and a CSS file defining some extra options.
I am working with JSP and JSPF, and for some reason (possibly the difference between the two?) when I put <script> tags in the JSPF file I am working with they do not run when the page loads. I figured I would sort this out later and in the meantime just to test other stuff I put code in the header JSP file that does run script tags.
dojo.require("x.y.z");
<div
id="testDiv"
dojoType="x.y.z" onclick="dojo.parser.parse()">abc</div>
This works the way I want it to. There’s a div, and when I click on it it loads the dojo widget with the template I defined.
In the JSPF file, I put the same div (abc), and then I also did something similar, but going up another step:
<div onclick="
dojo.require('x.y.z');
var n = document.createElement('div');
n.setAttribute('id', 'xyz');
n.setAttribute('dojoType', 'x.y.z');
n.setAttribute('onclick', 'dojo.parser.parse()')
n.innerHTML = 'Test';
document.body.appendChild(n);
">Click Me Please!</div>
The reason I put this in was that when I had just abc, it was giving me the following errors in Firebug:
Error parsing in _ContentSetter#Setter_1:13_0
Error: Could not load class 'x.y.z
Error undefined running custom onLoad code: This deferred has already been resolved
undefineddojo._scopeArgs = [undefined];
I figured this was because x.y.z was not being dojo.require’d, unlike the JSP when it was, and since I couldn’t get javascript to run automatically in jspf, I wrote “Click me please” to hackishly require in the onclick and then do the same thing, just to try to test things and get them working.
The idea of the second one was that I should be able to click on it and have the div appear from before. It seems to do the require fine and creates the div, but then when I click on the div it says
Tried to register widget with id==(numbers) but that id is already registered
So I figured that this was because I was just running dojo.parser.parse over everything, and it was catching things already on the page – really I should just run it on the new thing I made. So I was trying to figure out how to do dojo.parser.parse on just one thing. I found information for 1.8 and 1.7 but not 1.6. How can I do this, and am I understanding things correctly and making good assumptions?
Means you are calling
requirefor a class which is not found in package description location. x.y.z translates into a relative path from the dojo.js file (included via script-tag) as follows:Since class fails to load, proable cause is file does not exist and you have a HTTP 404 error.
In terms of this error message:
This means that you have created the widget (you set unique id: testDiv) twice. Probably because div onclick is called twice.. dijit widgetId’s must remain unique – and if you desperately need to create a new one with same
id, calldijit.byId(id).destroy();first.Easy out is to leave no
idin your markup, then a generic auto-incrementing id will be generated.