Opened 13 years ago

Closed 12 years ago

#1343 closed defect (wontfix)

createWidget Bug?

Reported by: ole_ersoy@… Owned by: bill
Priority: high Milestone: 0.9
Component: Widgets Version: 0.3
Keywords: Cc:
Blocked By: Blocking:

Description

Overview:

The addChild method of MyWidget? should throw an exception if the child is not of a valid widget type.

I tested it as follows (The test html document and Javascript code are pasted at the end of the email):

function testInvalidChildException() {

var myWidgetInstance = dojo.widget.createWidget("MyWidget?", {}); var button = dojo.widget.createWidget("Button", {}); alert(button.widgetType); try {

myWidgetInstance.addChild(button);

} catch(e) {

Test Passed

}

}

Testing results in this error:

  1. testMyWidget.html:testInvalidChildException had an error

Error message is: "[Exception... "Component returned failure code: 0x80520012 (NS_ERROR_FILE_NOT_FOUND) [nsIXMLHttpRequest.send]" nsresult: "0x80520012 (NS_ERROR_FILE_NOT_FOUND)" location: "JS frame :: file:////home/ole/workspace/AExperiment/lib/dojo/dojo.js :: anonymous :: line 951" data: no]"

However, if I add this element below the script block the test passes:

<div dojoType="Button" id="ssitem"/>

Here is the Test File:

<!DOCTYPE html

PUBLIC "-W3CDTD XHTML 1.0 TransitionalEN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head>

<title>Resonance Accordion Testing</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <script language="JavaScript?" type="text/javascript">

Dojo configuration djConfig = {

isDebug: true

};

</script> <script

type="text/javascript" src="lib/dojo/dojo.js">

</script> <script

type="text/javascript" src="lib/jsunit/app/jsUnitCore.js">

</script> <script language="JavaScript?" type="text/javascript">

dojo.hostenv.setModulePrefix('com', '../../com'); dojo.require('dojo.widget.*'); dojo.widget.manager.registerWidgetPackage('com.MyWidget?');

dojo.require('com.MyWidget?'); dojo.require('dojo.widget.Button');

</script>

</head> <body>

<div dojoType="MyWidget?" id="test"> </div>

<script>

function testInvalidChildException() {

var myWidgetInstance = dojo.widget.createWidget("MyWidget?", {}); var button = dojo.widget.createWidget("Button", {}); alert(button.widgetType); try {

myWidgetInstance.addChild(button);

} catch(e) {

Test Passed

}

}

</script>

<!--

<div dojoType="Button" id="ssitem"/> -->

</body> </html>

Here is the MyWidget? widget. Note that the directory "com" is in the same root directory as "lib". And lib contains the "dojo" directory and the "jsunit" directory.

Here is the MyWidget?.js package:

dojo.provide("com.MyWidget?"); dojo.require("dojo.widget.HtmlWidget?"); dojo.require("dojo.widget.*");

dojo.widget.defineWidget(

"com.MyWidget?", dojo.widget.HtmlWidget?,

{

widgetType: "MyWidget?", isContainer: true, allowCollapse: false, templateString: "<div dojoAttachPoint='containerNode'></div>",

addChild: function(widget) {

if (widget.widgetType != "WidgetItem?") {

dojo.debug("The Widget Contains items that are not AccordionItem? items"); throw InvalidChildException?;

} else {

this.addWidgetAsDirectChild(widget); this.registerChild(widget); return widget;

}

},

postCreate: function() {

var childBuffer = this.children; this.children=[]; dojo.html.removeChildren(this.domNode); dojo.lang.forEach(childBuffer, dojo.lang.hitch(this,"addChild"));

},

}

); InvalidChildException? =new Error ("Invalid Child Widget");

Attachments (2)

testMyWidget.html (1.3 KB) - added by ole_ersoy@… 13 years ago.
MyWidget.js (929 bytes) - added by guest 13 years ago.

Download all attachments as: .zip

Change History (4)

Changed 13 years ago by ole_ersoy@…

Attachment: testMyWidget.html added

Changed 13 years ago by guest

Attachment: MyWidget.js added

comment:1 Changed 13 years ago by dylan

Milestone: 0.5

comment:2 Changed 12 years ago by bill

Resolution: wontfix
Status: newclosed

There are a lot of error conditions we could check for throughout the dojo code, but we've decided not to in general, because it's easy enough to see what the error is w/the debugger, and adding throw statements actually makes debugging in IE harder

Note: See TracTickets for help on using tickets.