It's all about the answers!

Ask a question

Modern Dojo(AMD Notation) causing troubles (Widget creation) with IBM Modules


Jonas Studer (207917) | asked Jan 09 '15, 11:00 a.m.
edited Jan 14 '15, 5:52 a.m.
Dear Community,

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



permanent link
Jonas Studer (207917) | answered Jan 14 '16, 4:51 a.m.
Hy there fellas,

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,

-1
permanent link
Donald Nong (14.5k614) | answered Jan 12 '15, 6:31 p.m.
Any reason you want to use AMD, as Dojo 2.0 has not been released yet? As far as I can tell, the latest CLM 5.0.2 still uses Dojo 1.8.4. And for this version, you need to load Dojo with "async:true" to use AMD. But I don't see CLM load Dojo this way, and am not sure how you can change the way it loads Dojo.

Comments
Jonas Studer commented Jan 14 '15, 5:58 a.m.

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.


Donald Nong commented Jan 14 '15, 11:11 p.m. | edited Jan 14 '15, 11:12 p.m.

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).


Jonas Studer commented Jan 15 '15, 4:15 a.m.

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)."


Jonas Studer commented Jan 15 '15, 4:16 a.m.

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)."

Your answer


Register or to post your answer.


Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.