Creating Dynamically Populated Table RowsThis 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. PageThis example is a page that shows current threads: HTMLTo 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"> </span> </td> <td> <span class="isAlive">Y</span> <span class="isNotAlive"> </span> </td> <td> <span class="isInterrupted"> </span> <span class="isNotInterrupted">Y</span> </td> </tr> </table </body> </html> Dynamator FileAs 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 fileAfter processing with Dynamator, the resulting JSP file looks like this: CurrentThreads.jsp (generated by
Dynamator)
In ActionIf you are viewing this page in a servlet engine, you can see the generated page in action. |
||||||
Page last updated 01 April 2004 |
Copyright 2001-2004 by Jay Dunning. All rights reserved. |
hosted by |