IBMlogo
IBM eNetwork Communications Server for Windows NT
Host Publisher Feature, Version 6.01
[Next|Previous|Contents]

Host Publisher Hints and Tips

Scripting

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.

Generating a Web page

When the Page Server processes a Web page containing DYNASCRIPT tags, it executes each DYNASCRIPT section using whatever language is specified, and replaces that part of the Web page with the output from the DYNASCRIPT section. Output in JavaScript is produced using Document.Write(), Document.Writeln(), and related methods.

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:


Today is 11 Aug 1998 ; tomorrow is a new day.

Note that using a DYNASCRIPT tag has several advantages over direct use of JavaScript in a Web page:

  1. Other scripting languages are supported
  2. Access to Host Publisher integration objects
  3. Script code is never sent to the end user's browser, so the end user cannot see it even by viewing the HTML source of the Web page.

Accessing integration objects

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();
}

Communicating with Integration Objects

Some integration objects can access session variables and Web form parameters. For example, the Java SIM can pass the value of a session variable or a Web form parameter as an argument to a Java call.

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.

Communication Example

Here is an example in which data is retrieved from one integration object and passed to another:
<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>

Data post-processing and formatting example

Here are some techniques that would be difficult to accomplish without scripting:
  1. If a query returns no data, it is nice to display a message, instead of showing an empty page.

  2. Sometimes it's easier to use Javascript to process the data from an integration object into the desired format than to get the integration object to return the data in exactly the desired format.

    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.

  3. After identifying the data items, use JavaScript to format the data into a table with rows having alternating background colors.

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

More

For another example, see the User ID management section.
[Next|Previous|Contents]
IBM eNetwork Communications Server for Windows NT
Host Publisher Feature, Version 6.01