<%@ page import="javax.sql.*"%>
<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean"%>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html"%>

<html:html>
	<head>
		<title><bean:message key="app.title" /></title>
		<html:base />
	</head>
<body>

	<!-- in case validation of the entry data fails in the data bean -->
	<html:errors />

	<table>
	<tr>
		<td valign="top">
			<%-- -------- Include menu HTML code -------- --%>
			<jsp:include page="../menu.jsp" />
		</td>
		<td>
			<!-- Add an HTML table header row to format the results -->
			<table>
			<tr>
				<th>UBID</th>
				<th>First Name</th>
				<th>Middle Name</th>
				<th>Last Name</th>
				<th>Action</th>
			</tr>
			<tr>
				<html:form action="/insertStudent">
					<td><html:text property="id" size="10" /></td>
					<td><html:text property="first" size="15" /></td>
					<td><html:text property="middle" size="15" /></td>
					<td><html:text property="last" size="15" /></td>
					<td><html:submit value="Insert" /></td>
					<td><html:reset /></td>
				</html:form>
			</tr>

			<%-- -------- Iteration Code -------- --%>
			<%
				// Get the studentsRowSet
				RowSet crsStudents = (RowSet) request.getAttribute("crsStudents");
		
				// Iterate over the RowSet
				while (crsStudents.next()) {
			%>

			<tr>
				<html:form action="/updateStudent">

					<%-- Get the ubid, which is a number --%>
					<td>
						<html:text	property="id" size="10"
									value="<%=crsStudents.getString(\"ubid\")%>"
									readonly="readonly" />
					</td>

					<%-- Get the first name --%>
					<td>
						<html:text	property="first" size="15"
									value="<%=crsStudents.getString(\"firstName\")%>" />
					</td>
	
					<%-- Get the middle name --%>
					<td>
						<html:text	property="middle" size="15"
									value="<%=crsStudents.getString(\"middleName\")%>" />
					</td>
	
					<%-- Get the last name --%>
					<td>
						<html:text	property="last" size="15"
									value="<%=crsStudents.getString(\"lastName\")%>" />
					</td>

					<%-- Button --%>
					<td><html:submit value="Update" /></td>
				</html:form>

				<html:form action="/deleteStudent">
					<html:hidden property="id" value="<%=crsStudents.getString(1)%>" />
					<td><html:submit value="Delete" /></td>
				</html:form>
			</tr>
			<%
				}
			%>
			</table>
		</td>
	</tr>
	</table>
</body>
</html:html>