我有一个任务来创建一个能够为办公室分配导师的 java ee 应用程序,我有两个实体类,一个名为 Tutors.java,另一个名为 Offices.java。下拉列表填充但是当我想分配这两个值并点击提交按钮时,它会在 java bean 中的 server.allocateTutorOffice 处抛出一个空指针。我意识到问题出在服务器类上,但我不确定如何更改它来解决问题。
TutorBean.java
public void allocateTutorOffice(){
server.allocateTutorOffice(tutor.getOfficeId(), tutor.getId());
tutor = new Tutors();
}
TutorServer.java
@Override
public void allocateTutorOffice(Offices officeId, int Id) {
Tutors t = manager.find(Tutors.class, Id);
//Offices o = manager.find(Offices.class, officeId);
e.setOfficeId(officeId);
manager.merge(t);
}
Staff maintence.jsp
<c:choose>
<c:when test="${not empty param.allocate}">
<fmt:parseNumber var="e" type="number" value="${param.e.id}" />
<fmt:parseNumber var="o" type="number" value="${param.o.id}" />
<c:set var="e" scope="request" value="${tutor.tutor}"/>
<c:set var="o" scope="request" value="${office.office}"/>
<jsp:setProperty name="e" property="officeId"/>
<% employee.allocateTutorOffice();%>
</c:when>
</c:choose>
<h2> Allocate Office</h2>
<jsp:useBean id="office" class="cmm502.cw.web.OfficesBean" scope="session"/>
<form method="post" action="StaffMaintence.jsp">
<table>
<tr>
<td>Employee Id:
<select>
<c:forEach var="e" items="${tutor.tutors}">
<option value="${t.id}">${t.id}</option>
</c:forEach>
</select>
</td>
<td>Office Id:
<select>
<c:forEach var="o" items="${office.offices}">
<option value="${o.id}">${o.id}</option>
</c:forEach>
</select>
<td>
<input type="hidden" name="id" value="${e.id}"/>
<input type="submit" name="allocate" value="allocate"/></td>
</tr>
</table>
</form>