Separating AW code from html markup

Early AW examples use document.write(obj) method to insert the control into html page. That may work fine with the small number of the controls (for example, the single AW grid on a page). However with the larger number of form controls having multiple small <script> blocks intermixed with html markup is not very good idea. In this case more efficient solution is to include placeholder html tags where the AW controls should be and later replace them with actual controls using refresh() method. For example,

<tr><td>Here is button 1 - <span id="button1"></span></td></tr>
<tr><td><span id="button2"></span> - and is button 2 </td></tr>


    var obj1 = new AW.UI.Button;
    obj1.setControlText("Button 1");

    var obj2 = new AW.UI.Button;
    obj2.setControlText("Button 2");


The only requirement here is assigning the same ID to the placeholder element and actual AW control.

Benefit of this method is full separation of the code and html markup - both javascript and html become much more readable and easier to manage.

Here is the modified AW controls example -



<!-- include AW library files -->
<script src="../../runtime/2.0/lib/aw.js"></script>
<link href="../../runtime/2.0/styles/xp/aw.css" rel="stylesheet"></link>

<!-- page/controls styles -->
    body {font: menu}

    #group1 {width: 300px; height: 50px}
    #grid1 {width: 400px; height: 100px}
<body class="aw-background-1">

<!-- page layout -->
        <td><p>Label:</p><span id="label1">To be replaced by AW object...</span></td>
        <td colspan="3"><p>Group:</p><span id="group1"></span></td>
        <td><p>Button:</p><span id="button1"></span></td>
        <td><p>Link:</p><span id="link1"></span></td>
        <td><p>Input:</p><span id="input1"></span></td>
        <td><p>Combo:</p><span id="combo1"></span></td>
        <td colspan="3"><p>Tabs:</p><span id="tabs1"></span></td>
        <td><p>Checkbox:</p><span id="checkbox1"></span></td>
        <td><p>List:</p><span id="list1"></span></td>
        <td><p>Checked List:</p><span id="checkedList1"></span></td>
        <td><p>Tree:</p><span id="tree1"></span></td>
        <td><p>Radio:</p><span id="radio1"></span></td>
<p>Grid:</p><span id="grid1"></span>

<!-- AW controls script -->

    var itemTextArray = ["Home", "Favorites", "Font size", "Search"];
    var itemImageArray = ["home", "favorites", "fontsize", "search"];

    var label = new AW.UI.Label;

    var group = new AW.UI.Group;

    var button = new AW.UI.Button;

//	...

    var grid1 = new AW.UI.Grid;

Alex (ActiveWidgets)
May 12,

This topic is archived.

See also:

Back to support forum


Version 2

Looking for AW 2.6 ?
The old site is here.