Example: Using RecordListRowData

This example has three parts:

Java source that shows how the RecordListRowData class works
         // Create a server object.
         AS400 mySystem = new AS400 ("mySystem.myComp.com", "UserId", "Password");

         // Get the path name for the file.
         QSYSObjectPathName file = new QSYSObjectPathName(myLibrary, myFile, "%first%", "mbr");
         String ifspath = file.getPath();
                                                                                                                                                                                      
         // Create a file object that represents the file.         
         SequentialFile sf = new SequentialFile(mySystem, ifspath);

         // Retrieve the record format from the file.
         AS400FileRecordDescription recordDescription = new AS400FileRecordDescription(mySystem, ifspath);
         RecordFormat recordFormat = recordDescription.retrieveRecordFormat()[0];

         // Set the record format for the file.
         sf.setRecordFormat(recordFormat);
         
         // Get the records in the file.
         Record[] records = sf.readAll();

         // Create a RecordListRowData object and add the records.
         RecordListRowData rowData = new RecordListRowData(recordFormat);

         for (int i=0; i < records.length; i++)
         {
            rowData.addRow(records[i]);
         }

         // Create an HTML converter object and convert the rowData to HTML.
         HTMLTableConverter conv = new HTMLTableConverter();
         conv.setMaximumTableSize(3);
         HTMLTable[] html = conv.convertToTables(rowData);

         // Display the first HTML table generated by the converter.
         System.out.println(html[0]);
HTML source generated from the Java source by the using HTMLTableConverter

Using the HTMLTableConverter class in the Java source example above generates the following HTML code.

<table>
<tr>
<th>CNUM</th>
<th>LNAM</th>
<th>INIT</th>
<th>STR</th>
<th>CTY</th>
<th>STATE</th>
<th>ZIP</th>
<th>CTLMT</th>
<th>CHGCOD</th>
<th>BDUE</th>
<th>CTDUE</th>
</tr>
<tr>
<td>938472</td>
<td>Henning </td>
<td>G K</td>
<td>4859 Elm Ave </td>
<td>Dallas</td>
<td>TX</td>
<td align="right">75217</td>
<td align="right">5000</td>
<td align="right">3</td>
<td align="right">37.00</td>
<td align="right">0.00</td>
</tr>
<tr>
<td>839283</td>
<td>Jones   </td>
<td>B D</td>
<td>21B NW 135 St</td>
<td>Clay  </td>
<td>NY</td>
<td align="right">13041</td>
<td align="right">400</td>
<td align="right">1</td>
<td align="right">100.00</td>
<td align="right">0.00</td>
</tr>
<tr>
<td>392859</td>
<td>Vine    </td>
<td>S S</td>
<td>PO Box 79    </td>
<td>Broton</td>
<td>VT</td>
<td align="right">5046</td>
<td align="right">700</td>
<td align="right">1</td>
<td align="right">439.00</td>
<td align="right">0.00</td>
</tr>
</table>
How a browser displays the generated HTML

The following table shows how the HTML source code looks when viewed in a browser.

CNUM LNAM INIT STR CTY STATE ZIP CTLMT CHGCOD BDUE CTDUE
938472 Henning G K 4859 Elm Ave Dallas TX 75217 5000 3 37.00 0.00
839283 Jones B D 21B NW 135 St Clay NY 13041 400 1 100.00 0.00
392859 Vine S S PO Box 79 Broton VT 5046 700 1 439.00 0.00