Modern Dojo(AMD Notation) causing troubles (Widget creation) with IBM Modules
I've got a little question about the modern dojo...
And it's usage.
1: Till now I've created widgets this way:
dojo.provide("my.own.viewlet.web.Widget");
//This one is the Dashboardsuperclass,
dojo.require("com.ibm.team.dashboard.web.ui.Viewlet");
//Bsp: of requirements
dojo.require("dijit.MenuBar");
(function() {
var Viewlet = com.ibm.team.dashboard.web.ui.Viewlet;
var MenuBar = dijit.MenuBar;
//My Widget inhertits from the Viewlet
dojo.declare("my.own.viewlet.web.Widget", Viewlet, {
templatePath: dojo.moduleUrl("my.own.viewlet.web", "templates/template.html"),
2: But with the new AMD Notation I can't require the Viewlet anymore... why that?
It doesn't even load itself... and how would I set it as parent class?
define([
"dojo/_base/declare",
"dijit/_WidgetBase",
"dijit/MenuBar",
"com.ibm.team.dashboard.web.ui.Viewlet",
], function(declare, _WidgetBase, Viewlet, MenuBar) {
return declare("my.own.viewlet.web.TestAmd", _WidgetBase, {
3: Not even the separate require won't load this thing
require(["com.siemens.bt.jazz.absence.viewlet.web.AbsencesViewlet"], function(ViewletTwo){
console.log("Inside Require");
console.log(ViewletTwo);
});
Please help me
2 answers
I stumbled across this old question. Now I have the solution for you.
The problem we have here is, that all of the IBM-Javascript-Classes are written in an old dojo version (at least they use the old syntax [Dojo < 1.7])
Therefore, if you use the AMD-Notations you'll get an "error" when you require old "Classes".
Here I show you the header of an AMD-Defined Widget.
I'm requiring the external Class "com.ibm.team.dashboard.web.ui.Viewlet".
This will fire this errorMessage: "Unresolved module with id: com.ibm.team.dashboard.web.ui.Viewlet"
And the attribute "Viewlet" between declare and domAttr will be EMPTY!
But you still can use it with "dojo.global".
dojo.global.com.ibm.team.dashboard.web.ui.Viewlet
This will do the trick.
define(["dojo/_base/declare",
"require",
"com.ibm.team.dashboard.web.ui.Viewlet",
"dojo/dom-attr",
"dojo/date",
"dojo/topic",
"dojo/on"
], function (declare, Viewlet, domAttr, Date, topic, on){
return declare("my.Widget", dojo.global.com.ibm.team.dashboard.web.ui.Viewlet, {
DEFAULTHEIGHT: 3,
SUPPORTEDBROWSER: null,
Comments
Hy Donald,
1: To ensure this... I'm talking about Javascript.
2: I don't get why you talk about Dojo 2.0 since the AMD-structure is since Dojo 1.7
"The Asynchronous Module Definition (AMD) format is the module format that Dojo adopted starting with Dojo 1.7"
http://dojotoolkit.org/documentation/tutorials/1.10/modules/
3: I've never used since now the "async:true" Parameter to load a class, but Asynchroneous loading weren't a Problem at all...
Even the normal Widget load's into the Dashboard.. so I guess this is wrong.
4: The thing I wanna know is how to load absolute paths in this new notation...
Based on my expirience it will work), because I've already loaded my classes there.
Just the IBM classes won't work thought.
I was referring to this article.
http://dojotoolkit.org/reference-guide/1.9/releasenotes/migration-2.0.html
Dojo 1.8 document also clearly says "async:true" is required.
https://dojotoolkit.org/documentation/tutorials/1.8/modules/
I have not done any actual coding with AMD, but from what I have read, from Dojo 1.7 onwards, you can use AMD notation to load modules, but it does not mean that it will translate the original global variables to modules. In other words, if you already have your classes/libraries written as modules, you can load them using the AMD notation; if they are the old format (global variables), you need to load them the old way (dot notation).
One thing I am not sure is whether you can mix the AMD notation with the dot notation (the way your wrote in case 2 & 3 in the original post).
Ok, thanks for calrification.
Dang, but exactely this is my problem :D
"One thing I am not sure is whether you can mix the AMD notation with the dot notation (the way your wrote in case 2 & 3 in the original post)."
Ok, thanks for calrification.
Dang, but exactely this is my problem :D
"One thing I am not sure is whether you can mix the AMD notation with the dot notation (the way your wrote in case 2 & 3 in the original post)."