contents

intro
overview
requirements
cgi basics

dyno cgi
cgi headers
cgi parameters
accessing files
pipe basics
substitution basics
more substitution
table substitution

Dyno CGI: Tables

TableSubstitutionAction

This FieldSubstitutionAction subclass is an abstract base class that needs to be subclassed to provide implementation of a couple of key methods for starting, iterating over, and ending the table. TOCFilesTableSubstitutionAction is one such subclass.

You can do some cool stuff by creating your own subclass. Basically, you'll need to override three methods:

  • BeginTable() -- Prepare to get your table data. For example, TOCFilesTableSubstitutionAction opens the TOC file here.
  • NextRow() -- Output one row. For example, TOCFilesTableSubstitutionAction reads a line from the TOC file to get the record ID, then gets the data from the record's file into the row's substitution fields, and finally outputs the even or odd row HTML through a pipe.
  • EndTable() -- Cleans up. For example, TOCFilesTableSubstitutionAction closes the TOC file here.

TOCFilesTableSubstitutionAction

This FieldSubstitutionAction subclass implements a simple text-file-based database reading capability to output dynamic data records into an HTML table whose layout is in an HTML file.

It starts with a "table of contents" text file. This file must contain one line per database record. The format of the line is simple a record identifier string. This string identifies the name of the file that contains the record's data. If you look at the code for TOCFilesTableSubstitutionAction, you can see that it wants the TOC file to be named table_of_contents.txt, and for the data files to be named <id>_data.txt where <id> is the record identifier string in the TOC file. You can change these if you like, or make a subclass of TOCFilesTableSubstitutionAction that overrides the accessors of these strings.

The data files are formatted like Java properties files: each line is of the format "property=value" (without the quotes), and in our case the property name is the Dyno CGI substitution variable name, and the value is the string that it will be replaced with for this record.

To format the table, you simply need to create a table in the HTML file. You can create a "header" row that contains column names if you wish. Then, you need to create one row that is preceded by a marker <!--&begintablerow0-->, specifically before the <tr> tag that starts the row. Format the row to look however you want, and put variable markers where you want them in the row. Typically you'll use a variable marker in each cell to contain the data from the record file. If you want to, you can create a second row that is preceded by a marker <!--&begintablerow1-->, specifically after the </tr> tag ends the previous row, and before the <tr> tag that starts this row. You can format this row differently from the previous one, and the substitution action (actually the superclass TableSubstitutionAction) will alternate rows between the two formats you've used. If you use one formatting row rather than two, you must follow its terminating </tr> tag with a marker <!--&endtablerow-->, and if you use two formatting rows, you must put this marker after the terminating </tr> tag of the second formatting row. This lets the substitution action know where the per-record HTML starts and ends.

You may want to subclass TOCFilesTableSubstitutionAction if you need to convert any fields of the database records. For example, you might want to change a numeric string to a graphic indicator.

Check out Example 05 for a lot of detailed comments about how this works.