-1

私は、家庭教師をオフィスに割り当てる機能を備えたjava eeアプリケーションを作成する割り当てを持っています。1つはTutors.javaと呼ばれ、もう1つはOffices.javaと呼ばれる2つのエンティティクラスがあります。ドロップダウンが表示されますが、2つの値を割り当てて送信ボタンを押すと、JavaBeanのserver.allocateTutorOfficeにnullポインターがスローされます。問題はサーバークラスにあることはわかっていますが、問題を解決するためにサーバークラスを変更する方法がわかりません。

 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>
4

1 に答える 1

0

I think the object "server" is of type TutorServer. Please try to instantiate that object by doing server = new TutorServer() and then call the method allocateTutorOffice(). But i feel that you are invoking a business functionality from a bean class which is not a good design.

于 2012-04-20T21:36:38.553 に答える