Have you ever encountered initialization error in building dojo application? . Most frequent errors are ; dojo is not loaded,getElementByid("..")/dojo.byId("..") is null or not an object, dijit widget is not loaded etc etc. It's certain that there is something wrong in parsing HTML, but it's not as easy to rectify like traditional HTML web pages.

Scenario


You are using dojo.byId("..") or document.getElementById("..") on OnLoad event of the form and ended up with "dojo.byId("..") not defined or not an object" error. This is very common use of OnLoad event in Domino web applications.


Something about dojo.addOnLoad()


Dojo's addOnLoad() makes sure that the DOM tree has been built by the browser and any other JavaScript that the handler references has been downloaded and evaluated.In dojo application we need to make sure that JavaScript resources that we’ve dojo.required and/or the DOM tree are ready for use.


What dojo.addOnLoad does ?


dojo.addOnLoad takes a reference to a function and guarantees that the provided function is executed immediately after the following three conditions are met:

# The DOM tree has been built by the browser and is available for use by client code.

# All JavaScript resources demanded through the Dojo loader have been loaded.

# All Dojo widget parsing has been completed.Dojo lets you specify widgets directly in the HTML code. When you include Dojo widgets , Dojo must parse the HTML and replace each embedded widget with the actual HTML that implements the widget.
If djConfig.parseOnLoad is true, then this is accomplished as soon as the DOM tree is loaded by the browser but before any function registered with dojo.addOnLoad is executed.

Facts in using dojo.addOnLoad()


# dojo.addOnLoad can be used any number of times.

# Each function given as an argument in dojo.addOnLoad() will be executed in the order it was provided.

Solution


# Scenario 1 : Setting up value in variable(s) or pop-up alert to the user on onLoad event of the form.

Instead of ,



use like,



# Scenario 2 : Calling JavaScript function on onLoad event of the form ,

Instead of ,



use like,



# Scenario 3 : Attaching JavaScript function to any object on any event



( Note:JavaScript code is not allowed in the blog, write me for actual code )

Leave a Reply

preload preload preload