<%@ page import="org.w3c.tools.jdbc.*" %>
<%@ include file="config.jsp" %>

<!-- initialize moviebean and specify the table name "movies" -->
<jsp:useBean id="moviebean" class="MovieBean" scope="request">
    <%
        JdbcBeanUtil.initializeBean(configbean, moviebean, "movies");
    %>
</jsp:useBean>

<!-- initialize actorbean and specify the table name "actors" -->
<jsp:useBean id="actorbean" class="ActorBean" scope="request">
    <%
        JdbcBeanUtil.initializeBean(configbean, actorbean, "actors");
    %>
</jsp:useBean>

<!-- initialize starringbean and specify the table name "starrings" -->
<jsp:useBean id="starringbean" class="StarringBean" scope="request">
    <%
        JdbcBeanUtil.initializeBean(configbean, starringbean, "starrings");
        starringBean.setMovieBean(moviebean);
        starringBean.setActorBean(actorbean);
    %>
</jsp:useBean>

<!-- set properties -->
<jsp:setProperty name="actorbean" property="*" />

<!-- html starts here -->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><html>
  <head>
    <title>Search movies</title>
  </head>
  <body>
<%
    if (request.getMethod().equals("POST")) {
        JdbcBeanSerializer serializer = starringbean.getSerializer();
        serializer.select();
        if (serializer.first()) {
            do {
%>
    <!-- display result -->
    <jsp:getProperty name="moviebean" property="title"/>,
    (<jsp:getProperty name="moviebean" property="year"/>)<br>
    Directed by <jsp:getProperty name="moviebean" property="director"/>
    <hr>
<%            
            } while (serializer.next());
        }
    } else {
%>
    <h1>Search movies starring:</h1>
       <form method="POST">
       <table border="0">
       <tr>
       <td>Actor's Firstname : </td><td><input type="text" name="firstname"></td>
       </tr><tr>
       <td>Actor's Lastname: </td><td><input type="text" name="lastname"></td>
       </tr><tr>
       <td colspan="2"><input type="submit"></td>
       </tr>
       </table>
    </form>
<%
    }
%>
    <hr>
  </body>
</html>
