<%@ page contentType="text/html; charset=Shift_JIS" %>
<%@ page import="javax.naming.*,
                 java.text.*,
                 java.util.*,
                 trail.entity.beans.*,
                 trail.entity.basic.*"%>

<%!
  private Calculator cal = null;
  private NumberFormat nf = null;

  public void jspInit () {
    try {
      InitialContext ctx = new InitialContext();
      cal = (Calculator) ctx.lookup(
                  "EJB3Trail/EntityCalculator/local");
    } catch (Exception e) {
      e.printStackTrace ();
    }

    nf = NumberFormat.getInstance();
    nf.setMaximumFractionDigits(2);
  }
%>

<%
    if ("AddInvestor".equals(request.getParameter("action"))) {
        cal.addInvestor (request.getParameter("investorname"),
            Integer.parseInt(request.getParameter("investorstart")),
            Integer.parseInt(request.getParameter("investorend")));
    }
%>

<html><body>

<p>個人投資家を追加する:<br/>
<form action="addinvestor.jsp" method="POST">
  名前 : <input type="text" name="investorname" value=""><br/>
  開始年齢 = <input type="text" name="investorstart" value="25">
  終了年齢 = <input type="text" name="investorend" value="65">
  <input type="hidden" name="action" value="AddInvestor"><br/>
  <input type="submit" value="個人投資家を追加する">
  <INPUT type="button" value="閉じる" onClick="window.close()">
</form><br/>

<%
  // Collection <Investor> investors = cal.getInvestors();
  Collection investors = cal.getInvestors();
%>

<%=investors.size()%></b>人の個人投資家がデータベースに登録されています。<br/>

<table>
<tr>
<td>名前</td>
<td>開始年齢</td>
<td>終了年齢</td>
</tr>

<%
    for (Iterator iter = investors.iterator(); iter.hasNext();) {
    Investor investor = (Investor) iter.next();
%>

<tr>
<td><%=investor.getName()%></td>
<td><%=investor.getStartAge()%></td>
<td><%=investor.getEndAge()%></td>
</tr>

<%
  }
%>
</table></p>

</body></html>