Saturday, September 05, 2009

Dojo tip for debugging partly "undefined" widgets

Yesterday I stumbled upon a common Dojo problem: Dojo is refusing to create twice a widget ending with undefined (result looked like widgettype0undefined). I ended up searching a long time what code I could have forgotten, what variable could have been missing in inherited classes,... I asked colleagues and the few ones who knew Dojo had no standard explanation for that problem. "Hard to find", "Search the call stack". All that brought nothing. The Dojo "call stack" just stays on the dojo.js file... very helpful.

Well, it turns out this "call stack" thing was the base for the solution. Thinking about templates and static programming, I began searching by making a dijit.byId(xxxx0undefined) in the Firebug console. From there, the solution was to walk up the nodes in the DOM model, and the parents a few levels up showed me what was missing. Some elements didn't have a name - because I selected the wrong NLS file. Bummer.

Well, Dojo experts probably know that already, but I think many developers are in need of such tricks. Hope it helps...