EagerLearner167 0 Newbie Poster

I'm a student. I am trying to make simple project for online borrowing book system.

Basically the flow is from Borrow.jsp (The user select which data their want to update)
The UpdateBorrowBinder.java will grab the object and pass to sql then bring the result to appear in UpdateBorrow.jsp

But the error shows nullpointerexception. I the form cant be posted. Can anyone help me? Thank You!!

This is Borrow.jsp

<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="f" %>

<form action="${ pageContext.request.contextPath }/action/?rid=UpdateBorrow" method="post">
<div>
<center>
<div>
<table>
	<tr>
		<td>Student Name</td>
		<td>:</td>
		<td>${ studBorrow.studName }</td>
	</tr>
	<tr>
		<td>Student Course</td>
		<td>:</td>
		<td>${ studBorrow.studCourse }</td>
	</tr>
	<tr>
		<td>Quantity Borrowed</td>
		<td>:</td>
		<td>${studBorrow.bookQtty }</td>
	</tr>
</table>
</div>
<br>
<table border="1">
<tr>
	<td><b>&nbsp;</b></td>
	<td><b>Book ID</b></td>
	<td><b>Book Title</b></td>
	<td><b>Date borrowed</b></td>
	<td><b>Date Returned</b></td>
	<!--<td><b>Action</b></td>  -->
</tr>
<c:forEach items="${ Borrow }" var="item">
	<tr>
		<td><input type="checkbox" name="selectedBook" value="${ item.bookId }"></td>
		<td>${ item.bookId }</td>
		<td>${ bookTitle[item.bookId] }</td>
		<td><f:formatDate pattern="dd MMM yyyy" value="${ item.borrowDate }"/></td>
		<td>${ item.returnDate }</td>
		<!-- <td><a href="?rid=UpdateBorrow&book_id=${ item.bookId }"> Update</a></td> -->
	</tr>
</c:forEach>
</table>
<a href="?rid=home">Home |</a> 
<button id="updateButton" onclick="document.location='?rid=UpdateBorrow">Update</button>
</center>
</div>
</form>

This is Borrow.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sqlMap PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN" "http://ibatis.apache.org/dtd/sql-map-2.dtd" >
<sqlMap>
	<typeAlias alias="Borrow" type="bookstore.servlet.domain.Borrow"/>
	
	<resultMap class="Borrow" id="borrow">
		<result property="bookId" column="book_id"/>
		<result property="studentId" column="stud_id"/>
		<result property="borrowDate" column="Borrow_date"/>
		<result property="returnDate" column="Return_date"/>
	</resultMap>
	
	<select id="getBookIdList" parameterClass="String" resultMap="borrow">
		SELECT *
		FROM borrow
		WHERE book_id=#bookId#
	</select>
	
</sqlMap>

This is UpdateBorrowBinder.java

public class UpdateBorrowBinder extends BaseBindingHandler {

	@Override
	public void handle(BindingHandlerEvent event) throws ServletException {
		try{
				String[] selectedBook = event.getParameterValues("selectedBook");
				List<?> b = null;
				
				for(int i = 0; i < selectedBook.length;i++ )
				{
					String id = selectedBook[i];
					b = sqlMap.queryForList("getBookIdList", id);
					System.out.println("Book id " + selectedBook[i]);
				}
				event.bind("borrowList", b);
			
			} catch (Exception e){
				throw new ServletException(e);
			}
		
	}
}

This is UpdateBorrow.jsp will appear the output

<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="f" %>

<div align="center">
	<table border="1">
	<c:forEach items="${ borrowList }" var="Borrow">
		<tr>
			<td><b>Book ID</b></td>
			<td>:</td>
			<td><input type="text" name="bookId" value="${ Borrow.bookId }"></td>
		</tr>
		<tr>
			<td><b>Date borrowed</b></td>
			<td>:</td>
			<td>
				<input type="text" name="borrowDate" 
				value="<f:formatDate pattern="dd MMM yyyy" value="${ Borrow.borrowDate }"/>">
			</td>
		</tr>
		<tr>
			<td><b>Date Returned</b></td>
			<td>:</td>
			<td><input type="text" name="returnDate" 
			value="<f:formatDate pattern="dd MMM yyyy" value="${ Borrow.returnDate }"/>"></td>
		</tr>
	</c:forEach>
	</table>
</div>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.