You can use the Web Data Window JavaScript Generator wizard to create JavaScript files (at design time) that contain the JavaScript client-side methods. You can start the Web Data Window JavaScript Generator wizard by clicking the Generate File button in the JavaScript Generation property page of the DataWindow property view or from the Tool tab of the New dialog box.
These JavaScript files (HTML/XHTML) are shared by all Web formats of the Web DataWindow—XML, XHTML, and HTML.
Each pass of the wizard generates only one file—which allows you to combine or separate classes of functions. Once you have generated one or more JavaScript files, you can attach them to a DataWindow object using the Filename drop-down lists (for Common Class, Date Time Management, Number Format, String Format, and User Class) in the JavaScript Generation property page. Generating and associating JavaScript files with a DataWindow object enables the JavaScript functions to be cached and then reused each time the page containing the DataWindow object displays in the browser.
To configure the JavaScript generation properties that are only for the XML Web DataWindow and XHTML Web DataWindow, you select XHTML and provide the resource base and the publish path:
When you set new DataWindow properties to reference included JavaScript files, the methods defined in the referenced files are not generated with the HTML in any Web DataWindow pages that are sent to the page server and client browser. Using JavaScript files also reduces the size of the HTML page rendered in the browser.
With JavaScript caching, you improve performance on the client machine as long as the client browser is configured to use cached files. With caching enabled, the browser loads the JavaScript files from the Web server into its cache, and these become available for all the Web DataWindow pages in your application. There is no client-side performance gain if the browser does not find the JavaScript files in its cache since, in this case, it reloads the files from the Web server.
With the Web DataWindow JavaScript Generator wizard, you can generate only one JavaScript file at a time. The wizard gives you the option of including all Web DataWindow methods in a single file, but you can also restrict the types of methods to include in each JavaScript file it generates every time you use the wizard. The different method types correspond to the following DataWindow HTML properties:
HTMLGen.property |
Contents of cached file |
---|---|
CommonJSFile |
Methods used by all DataWindows. |
DateJSFile |
Methods used by DataWindows with date and time formatting. |
NumberJSFile |
Methods used by DataWindows with number formatting. |
StringJSFile |
Methods used by DataWindows with string formatting. |
UserJSFile |
User-defined client-side JavaScript methods—these cannot be generated by the Web DataWindow JavaScript Generator wizard (see “User-defined JavaScript methods”). |
All of these properties are optional. You can set each of the properties from the JavaScript Generation page of the DataWindow property view, selecting the files you generate with the wizard as values. The wizard registers each file it generates, making it available for selection from the drop-down lists in the DataWindow property view.
You must deploy all cached files for your Web application to your Web server. You can use relative URLs or path names for cached JavaScript files if you specify their location in the HTMLGen.ResourceBase property.
You set these on the JavaScript Generation page of the DataWindow property view in the DataWindow painter. The ResourceBase property is also used to specify the location of image files.
If you do not set the HTMLGen.ResourceBase property, you must include the complete URL in the values of any of the HTMLGen properties that you set. In either case, the URLs are rendered as SRC attributes inside SCRIPT tags in the pages generated by the Web DataWindow component and sent to the client browser.
You can customize the DataWindow HTML Generator component (nv_remote_datawindow in PBDWRMT.PBL that ships with PowerBuilder), setting the HTMLGen properties in the script for the Generate method. This example sets the URL location for included files and names the files for common and date-formatted Web DataWindow methods that you deploy to the Web server (and that will be downloaded to browser clients the first time they connect to the Web site):
ids_datastore.Modify & ("DataWindow.HTMLGen.ResourceBase=" +& "'http://www.myserver.com/JavaScripts'") ids_datastore.Modify & ("DataWindow.HTMLGen.CommonJSFile=" +& "'dwcomn.js'") ids_datastore.Modify & ("DataWindow.HTMLGen.DateJSFile=" +& "'dwdate.js'")
You can also reference a file where you store your own client-side JavaScript methods. To use this feature, you must assign the name of the file to the DataWindow HTMLGen.UserJSFile property and make sure the file is available to your Web server. As for the wizard-generated JavaScript files, you can use the HTMLGen.ResourceBase property to set the location for the file, or you can include the complete path to the file in the property value assignment.
You can make this assignment in the DataWindow painter or in script. The following script sets the user-defined JavaScript file to MyMethods.JS:
ids_datastore.Modify & ("DataWindow.HTMLGen.UserJSFile=" +& "'http://my_server.com/JavaScripts/MyMethods.JS'")
This example will be rendered in the generated HTML page as:
<SCRIPT LANGUAGE="JavaScript" SRC= "http://my_server.com/JavaScripts/MyMethods.JS"> </SCRIPT>
You can then call client-side methods stored in the MyMethods.JS file from the HTML syntax rendered for (or appended to) controls in a DataWindow object. For information on generating or appending HTML syntax to controls, see “Rendering HTML for controls in an HTML Web DataWindow”.