Share via


Understanding the DhElement Class

Elements are objects derived from DhElement, which is the superclass of all user interface elements in the com.ms.wfc.html package. There is a certain consistency you can count on when using any object derived from DhElement:

  • Every element has an empty constructor. Therefore, you can instantiate any element with a new statement and then set properties, hook event handlers, and call methods consistently.

  • Elements are modeless. Setting properties or calling methods always works in any order and is not conditional on some external state or circumstance.

  • Every container has an add method that takes the type-safe element that is appropriate for it.

  • In the browser environment, an element does not become visible to the end user until you add it (or the topmost container element in its parentage) to the document. However, this is merely an artifact and not part of the programming model. You don't have to change the way you program to elements because they work the same way whether they are visible or not.

If an element is already on the page when the DhDocument.onDocumentLoad method is called, you can call the document's findElement method and start programming to that element. You can also call setBoundElements from initForm to merge known elements on the page with elements in your DhDocument-derived class. (The findElement method has better performance but specifically requires that onDocumentLoad is called first.)

The searching routine used by findElement and setBoundElements assumes that the element you want to bind to has an ID attribute set to a particular name. Using findElement, you can also enumerate all the elements in the document until you find the one you are interested in.