Dynamic Table CGI

The Dynamic Table CGI is a support CGI for HTML applications. The purpose of this CGI is to create a dynamic table from a NetPhantom list box, using different templates for each row. Below is an example of a list box where the header is displayed every time the first digit in the customer ID changes.

Click here to run the sample application.

Click here to view the Java source code.

The CGI is made to simplify this process, but it still requires some work. One column in the list box must contain the short name of the template for that row; this is usually handled from REXX.

Template files

Each row in the list box uses one HTML template file. The template file should contain ordinary HTML code and could also include special variables, much like the NetPhantom HTML variables.

This is an example of the HeaderTemplate.html file from above:

<TR>
  <td bgcolor="00AAFF" align="left"><i>Customer</i> </td>
  <td bgcolor="00AAFF" align="left"><i>Name</i> </td>
  <td bgcolor="00AAFF" align="left"><i>Last purchase</i> </td>
  <td bgcolor="00AAFF" align="right"><i>Amount</i> </td>
</TR>    
<TR>
  <td>@*_2;</td>
  <td>@*LINK_OK;> @*_3; </A></td>
  <td>@*_4;</td>
  <td align="right">@*_5;</td>
</TR>

Template variables

Template variable always start with "@*" and end with ";".

Example Description
@*_nn; Is replaced with the content of current list box row, column nn, example "@*_2;".
@*LINK_BUTTON; Creates a hyperlink (<A href=...) with npSelectAction="BUTTON" using the control ID BUTTON. Note that the hyperlink tag is not closed in case you want to add attributes in the template. In the example, a tag closing ">" is placed directly after the @*LINK_BUTTON; and a tag is placed after the text that should work as hyperlink.
@*@NPVariable@; All NetPhantom variables can be placed within the "@*" and the ";". For example, "@*@HOSTFLD@;" is replaced with the contents of the host field HOSTFLD.

NetPhantom CGI

Insert the class using the Server Administration client menu item Server – Configure – Web server. On the CGI tab Specify Name DYNTABLE, Java class name se.entra.phantom.server.http. DynamicTableCGI.class and check the HTML included CGI checkbox.

List box

The list box must contain a column in which REXX code can insert the short name of the template for each row (see the Template column in the example below). The first column is searched by default.

Include HTML file reference

The CGI is referenced from the HTML file for the current panel (in this case "CUSTSRCH").

Syntax of include statement:

<%@include cgi="DYNTABLE"
           listid="CTLID"
           [listboxcolumn=1..n]
           [ShortName1=FileName1]
           [ShortName2=FileName2]
           ...>

Parameters:
 
cgi Name of the cgi
listid List box control ID
listboxcolumn List box column index where template short name is found
shortName Conversion Short name to filename

Example:
 <%@include cgi   ="DYNTABLE"
            listid="LIST"
            head  ="HeaderTemplate.html"
            row   ="RowTemplate.txt">

Global variables

An alternative to using parameters in the @%include tag is to use NetPhantom Global Variables. All template shortcuts for an application can be created as global variables at application startup.

  /* Set listbox ID */
  ret = GlobVarSet('HTMLDYNAMICTABLE_LISTID','LISTID')

  /* EXAMPLE: Setup template file names */
  ret = GlobVarSet('HEAD','HeaderTemplate.html')
  ret = GlobVarSet('ROW','RowTemplate.html')

So what is the CGI good for?

The CGI can be used in different ways. It provides a flexible way of handling complicated lists. If you think about your own applications, you may find that it is the answer to problems you didn't know you had.

The sample shows how to use two different template files containing one or more HTML table rows. The actual <table> and </table> tags should be located in the main HTML file, not in the template.

Another way in which you could use the CGI is to create one table in every template file. You can also have more than one include in an HTML file. This could be useful when you have a list that contains rows that are too long to be contained on a single line and therefore require two lines per row in the host.

Usually two or three template files are used, but there is no limit. Try to create templates with names that are reusable throughout the application.

The following check list describes the basic steps required when using the DynamicTableCGI.

  1. Create a new panel with a non host connected list box in the Panel Editor.
  2. Add a template column that will contain the short name of the template used for each row. It should be the first column, unless you specify otherwise in the CGI include.
  3. Write REXX code that inserts list data. It should also insert the template short names in the template column.
  4. Create an HTML page for the panel. The HTML file should contain one or more CGI includes.
  5. Create the template files you will be using for the table.
  6. Check the CGI tab of the Configure-Web server dialog to ensure that the DYNTABLE CGI has been added. If it has not, add it yourself.