8.3 Current Watcher Listing

The code for the main user interface page, as shown in Example 8-3, is centered around looping over the results from the static method, AbstractWatcher.getSortedWatches( ).

Example 8-3. Main interface JSP
<%@ page contentType="text/html; charset=iso-8859-1" language="java" 

import="com.cascadetg.ch08.AbstractWatcher" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<title>Watches</title>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<link href="../ch04/www/default.css" rel="stylesheet" type="text/css" />

</head>



<body>

<table width="100%" border="0" cellpadding="3" cellspacing="3">

<tr>

  <td colspan="2"><strong>Target</strong></td>

  <td><strong>Last Update </strong></td>

  <td>&nbsp;</td>

</tr>

<tr><td colspan="4"><hr></td></tr>

<% 

AbstractWatcher[] myWatches = AbstractWatcher.getSortedWatches( );

if(myWatches != null)

{

if(myWatches.length > 0) {

for(int i = 0; i < myWatches.length; i ++ ) { 

%>



<tr>

<td width="20">&nbsp;</td>

<td> <%= myWatches[i].getHumanType( ) %><br />

    <%= myWatches[i].getTarget( ) %></td>

<td>

<small><%= myWatches[i].getLastUpdate( ).toString( ) %><br><%= 

myWatches[i].getFrequency( ) %></small></td><td>

<a href="delete.jsp?id=<%= myWatches[i].getID( ) %>">Delete</a>

</td></tr>

<% if(myWatches[i].getAttributes( ).size( ) > 0) { %>

<tr><td width="20">&nbsp;</td>

<td colspan="2"><small>

<% 

java.util.Iterator attributeKeys = myWatches[i].getAttributes( )

.keySet( ).iterator( );

while(attributeKeys.hasNext( ))

{

    String name = (String)attributeKeys.next( );

    String key = myWatches[i].getFormattedAttribute(name);

%>

<%= name %> : <%=key %><br>

<% } %>

</small>

</td><td>&nbsp;</td></tr><% } %>

<tr><td colspan="6"><hr></td></tr>

<% } } } %>

</table>

<p><a href="add_item.jsp">New Watcher</a> </p>

</body>

</html>

As shown in Figure 8-5, even a few defined watchers can start to overwhelm the default presentation. It's easy to envision adding additional user-interface functionality to deal with the data being mined, such as a Swing client or a more sophisticated DHTML design.

Figure 8-5. Several defined watchers
figs/rww_0805.gif