8.2 Deleting a Watcher

Figure 8-4 shows the confirmation form presented when a user clicks the delete link.

Figure 8-4. Deleting a watcher
figs/rww_0804.gif


The code to present the deletion form is shown in Example 8-2. A small amount of validation is performed at the top of the page; otherwise, the JSP is mostly concerned with the user interface.

Example 8-2. Deleting a watcher JSP
<%@ page contentType="text/html; charset=iso-8859-1" 

language="java" errorPage="" %>

<!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">

<%

    boolean delete = false;

    String productID = request.getParameter("productID");

    if(request.getParameter("Delete") != null)

        delete = true;

    

    boolean deleted = false;

    if(delete)

    {        

      deleted = 

        com.cascadetg.ch04.Search.removeSearch(productID);

    };

%>

<head>

<title>Chapter 4: Competitive Analysis</title>

<meta http-equiv="Content-Type" 

    content="text/html; charset=iso-8859-1" />

<link href="default.css" 

    rel="stylesheet" type="text/css" />

</head>

<body><% 

if (delete)

{ 

    if(deleted)

    {

%>

        <p>The item has been deleted.</p>

<%    } else {

%>        

        <p>Item not found.</p>

<%    }

} else{ %>

        <p>Are you sure you want to delete the 

            item "<%= productID %>"?</p>        

        <form name="deleteForm"  

            method="post" action="delete.jsp">

          <input type="hidden" name="productID" 

            value="<%= productID %>"/>

          <input name="Delete" type="submit" 

             value="Delete" />

         </form>

        <%

} 

%>

<p><a href="list.jsp">Return to list.</a></p>

</body>

</html>