filter.jsp
01 <%@ page import="javax.naming.*,
02                  java.text.*,
03                  java.util.*,
04                  trail.entity.beans.*, trail.entity.query.*"%>
05 
06 <%!
07   private Calculator cal = null;
08   private NumberFormat nf = null;
09 
10   public void jspInit () {
11     try {
12       InitialContext ctx = new InitialContext();
13       cal = (Calculatorctx.lookup(
14                   "EJB3Trail/QueryCalculator/local");
15     catch (Exception e) {
16       e.printStackTrace ();
17     }
18 
19     nf = NumberFormat.getInstance();
20     nf.setMaximumFractionDigits(2);
21   }
22 %>
23 
24 <%
25     Collection records;
26     if ("Filter".equals(request.getParameter("action"))) {
27         double low, high;
28         try {
29             low = Double.parseDouble(request.getParameter("low"));
30             high = Double.parseDouble(request.getParameter("high"));
31         catch (Exception e) {
32             low = 0.;
33             high = 0.;
34         }
35         records = cal.filterRecords (low, high);
36         // System.err.println("Filtered the records; low=" + low + " high=" + high);
37     else {
38         records = new ArrayList ();
39         // System.err.println("Empty records");
40     }
41 %>
42 
43 <html><body>
44 
45 <p>Search past calculation results<br/>
46 <form action="filter.jsp" method="POST">
47   From <input type="text" name="low" value="0">
48   To <input type="text" name="high" value="1000000">
49   <input type="hidden" name="action" value="Filter"><br/>
50   <input type="submit" value="Search">
51   <INPUT type="button" value="Close Window" onClick="window.close()">
52 </form><br/>
53 
54 <table>
55 <tr>
56 <td>Time stamp</td>
57 <td>Fund</td>
58 <td>Investor</td>
59 <td>Monthly savings</td>
60 <td><b>Total investment</b></td>
61 </tr>
62 
63 <%
64     for (Iterator iter = records.iterator(); iter.hasNext();) {
65         TimedRecord record = (TimedRecorditer.next();
66 %>
67 
68 <tr>
69 <td><%=record.getTs()%></td>
70 <td><%=record.getFund().getName()%></td>
71 <td><%=record.getInvestor().getName()%></td>
72 <td><%=nf.format(record.getSaving())%></td>
73 <td><%=nf.format(record.getResult())%></td>
74 </tr>
75 
76 <%
77     }
78 %>
79 </table>
80 
81 
82 </p>
83 </body></html>