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.

Page

This example is a page that shows current threads:

HTML

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

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

Dynamator File

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

CurrentThreads.dyn
<dynamator language="jsp">
  <prolog>
    <%@ 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;
        }
    %>
  </prolog>
  <class name="threads">
    <foreach i="iThreads" type="Thread[]" element="thread">
        threads
    </foreach>
    <attr name="id">
      <discard/>
    </attr>
  </class>
  <class name="name">
    <content>thread.getName()</content>
  </class>
  <class name="priority">
    <content>thread.getPriority()</content>
  </class>
  <class name="isDaemon">
    <if>thread.isDaemon()</if>
  </class>
  <class name="isNotDaemon">
    <if>!thread.isDaemon()</if>
  </class>
  <class name="isAlive">
    <if>thread.isAlive()</if>
  </class>
  <class name="isNotAlive">
    <if>!thread.isAlive()</if>
  </class>
  <class name="isInterrupted">
    <if>thread.isInterrupted()</if>
  </class>
  <class name="isNotInterrupted">
    <if>!thread.isInterrupted()</if>
  </class>
</dynamator>

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.