update.jsp
01 <%@ page import="javax.naming.*,
02                  java.text.*,
03                  java.util.*,
04                  trail.entity.beans.*, trail.entity.update.*"%>
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/UpdateCalculator/local");
15     catch (Exception e) {
16       e.printStackTrace ();
17     }
18 
19     nf = NumberFormat.getInstance();
20     nf.setMaximumFractionDigits(2);
21   }
22 %>
23 
24 <%
25     if ("Update".equals(request.getParameter("action"))) {
26         cal.updateExchangeRate(
27             Double.parseDouble(
28                 request.getParameter("newrate")));
29     }
30 %>
31 
32 <html><body>
33 
34 <p>Update the calculation records with a new currency<br/>
35 <form action="update.jsp" method="POST">
36   Exchange rate = <input type="text" name="newrate" value="1.5">
37   <input type="hidden" name="action" value="Update"><br/>
38   <input type="submit" value="Update">
39   <INPUT type="button" value="Close Window" onClick="window.close()">
40 </form><br/>
41 
42 All records from past calculations<br/>
43 <table>
44 <tr>
45 <td>Time stamp</td>
46 <td>Fund</td>
47 <td>Investor</td>
48 <td>Monthly savings</td>
49 <td><b>Total investment</b></td>
50 </tr>
51 
52 <%
53     Collection records = cal.getRecords ();
54     for (Iterator iter = records.iterator(); iter.hasNext();) {
55         TimedRecord record = (TimedRecorditer.next();
56 %>
57 
58 <tr>
59 <td><%=record.getTs()%></td>
60 <td><%=record.getFund().getName()%></td>
61 <td><%=record.getInvestor().getName()%></td>
62 <td><%=nf.format(record.getSaving())%></td>
63 <td><%=nf.format(record.getResult())%></td>
64 </tr>
65 
66 <%
67     }
68 %>
69 </table>
70 
71 </p>
72 </body></html>