The most flexible way to work with Host Publisher is using Javascript to generate your Web pages. From Javascript, you can invoke multiple integration objects, retrieve their data, and format the data any way you prefer.
This is an advanced topic and is not necessary for basic use of Host Publisher. You might wish to skip it for now.
This section assumes that you are somewhat familiar with HTML and JavaScript.
Start by browsing the DYNASCRIPT section, then review this section for some examples and tips.
For example, if the Page Server encountered a Web page that contained this HTML source:
<hr> Today is <strong> <DYNASCRIPT language=JavaScript> var today = new Date(); Document.Writeln(today.toLocalString()) </DYNASCRIPT> </strong>; tomorrow is a new day. <hr>
it sends the following HTML to the end user's browser:
<hr> Today is <strong> 11 Aug 1998 </strong>; tomorrow is a new day. <hr>
which is displayed as:
Note that using a DYNASCRIPT tag has several advantages over direct use of JavaScript in a Web page:
To work with an integration object from Javascript, you must create one, also called instantiating an object. Do this by calling IObjects.Get() and assigning the result to a variable, as follows:
var integration_object = IObjects.Get("name of integration object");
When you have created the integration object, you can retrieve the values of its data items using the GetItem() method:
var item_value = integration_object.GetItem("name of data item");
For SIMs that support multiple data rows, use the NextRow() method to advance to the next data row after retrieving the values of the data items from the current row. NextRow() returns false on the last row.
var value; var bMore = true; while (bMore) { value = integration_object.GetItem("name"); Document.Writeln("name=" + value); bMore = integration_object.NextRow(); }
Caution: Despite similarities, session variables are different from Web form parameters.
To set session variables, use calls such as
SESSION.SetProp("key name", "value")
Web form parameters can be passed to your Web page from a previous Web page containing a form. To access the values, use
var value = Environment.PARAMS.GetProp("key name")To set new values for Web form parameters, use
Environment.PARAMS.SetProp("key name", "value")
Be sure to set Web form parameters and session variables before instantiating the integration object that will use the data.
<html> <DYNASCRIPT language=JavaScript> Document.Writeln("<h1>Page heading</h1>"); // Instantiate one object var iObject1 = IObjects.Get("Integration Object 1"); // Get data from it var value = iObject1.GetItem("data item"); // Set an environment value. The Java SIM, for example, // can use environment values as input parameters Environment.PARAMS.SetProp("key name", value); // Instantiate another object var iObject2 = IObjects.Get("Integration Object 2"); // Get data var value2 = iObject2.GetItem("data item 2"); // Report the result Document.Writeln("<p>The result was " + value2); </DYNASCRIPT> </html>
This example assumes an integration object is querying a 3270 application, and the records are displayed in column formats that can vary somewhat in width. The integration object simply returns the entire line. The Javascript code finds the column boundaries and formats the results.
Assume the columns are space-separated.
Here is an example demonstrating all of these techniques:
<html> <DYNASCRIPT language=JavaScript> var iObject = IObjects.Get("integration object"); if (null == iObject.GetItem("line")) { Document.Writeln("No data was returned."); } else { var bMore = true; var row = 0; Document.Writeln("<table border=1>"); Document.Writeln("<tr bgcolor=\"#A09E47\"><th>Item1 <th>Item2 <th>Item3"); while (bMore) { if ((row % 2) == 0) { // alternate row colors Document.Writeln("<tr bgcolor=\"#F3EFB4\">"); } else { Document.Writeln("<tr bgcolor=\"#FFFFFF\">"); } ++row; var line = new String(iObject.GetItem("line")); var items = line.split(' '); var i = 0; while (i < items.length) { Document.Writeln("<td>" + items(i)); } bMore = iObject.NextRow() } Document.Writeln("</table>"); } </DYNASCRIPT> </html>
The result might look like this:
Item1 | Item2 | Item3 |
---|---|---|
data1 | data2 | data3 |
data1 | data2 | data3 |
data1 | data2 | data3 |
data1 | data2 | data3 |
data1 | data2 | data3 |
data1 | data2 | data3 |