Dynamator Pure HTML for every page generation technology.

Creating Dynamically Populated Table Rows

This example shows how to output the elements of a collection as rows of a table. Usually this is done when the elements are themselves objects with multiple attributes that merit display.


This example is a page that shows current threads:


To repeat table rows for each element of a collection, add a 'class' attribute to the the 'tr' element.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<title>Currently Executing Threads</title>
<table border=1>
  <tr align="center">
  <tr class="threads" align="center">
    <td class="name">thread-2</td>
    <td class="priority">5</td>
      <span class="isDaemon">Y</span>
      <span class="isNotDaemon">&nbsp;</span>
      <span class="isAlive">Y</span>
      <span class="isNotAlive">&nbsp;</span>
      <span class="isInterrupted">&nbsp;</span>
      <span class="isNotInterrupted">Y</span>

Dynamator File

As with the previous example, the Dynamator file uses the 'foreach' element:

<dynamator language="jsp">
    <%@ page session="false" %>
        ThreadGroup tg = Thread.currentThread().getThreadGroup();

        Thread[] threads = new Thread[tg.activeCount()];
        int n = tg.enumerate(threads);

        if ( n < threads.length )
            Thread[] newThreads = new Thread[n];
            System.arraycopy(threads, 0, newThreads, 0, n);
            threads = newThreads;
  <class name="threads">
    <foreach i="iThreads" type="Thread[]" element="thread">
    <attr name="id">
  <class name="name">
  <class name="priority">
  <class name="isDaemon">
  <class name="isNotDaemon">
  <class name="isAlive">
  <class name="isNotAlive">
  <class name="isInterrupted">
  <class name="isNotInterrupted">

JSP file

After processing with Dynamator, the resulting JSP file looks like this:

CurrentThreads.jsp (generated by Dynamator)

In Action

If you are viewing this page in a servlet engine, you can see the generated page in action.