0

I have the following jsf datatable which has a list of student courses, I want to get the selected row from that page so I have the following code for it but it keeps throwing null pointer exception can someone help with it?

here is my XHTML page:

            <p:dataTable paginatorPosition="bottom" id="tblClasses" var="course"
                value="#{mbStudent.lstStudentCourses()}" selectionMode="single"
                selection="#{mbStudent.course}" rowKey="#{course.id}"
                rowIndexVar="rowIndex" rows="6">
                <p:ajax event="rowDblselect" update="@parent:frm" process="@this"
                 listener="#{mbStudent.getSelectedRow()}"/>
                <p:column headerText="#" width="10%">
                #{rowIndex+1}
                </p:column>
                <p:column headerText="Course">
                    <p:outputLabel value="#{course.course.fullName}"></p:outputLabel>
                </p:column>
                <p:column headerText="Time" width="30%">
                    <p:outputLabel value="#{course.course.courseNumber}"></p:outputLabel>
                </p:column>
            </p:dataTable>

And here is my managed bean:

public List<CourseExamBank> lstStudentCourses() {
    GeneralFacade facade = new GeneralFacade();
    return facade.lstStudentClasses(getStudent());
}

public void getSelectedRow() throws IOException{
    CourseExamBank course = (CourseExamBank) dataTable.getRowData();
    System.out.println(course);
}

public String onFlowProcess(FlowEvent event) throws IOException {
    return event.getNewStep();
}

And here is the error I get:

WARNING: /pages/students/student_home.xhtml @19,49 listener="#{mbStudent.getSelectedRow()}": java.lang.NullPointerException javax.el.ELException: /pages/students/student_home.xhtml @19,49 listener="#{mbStudent.getSelectedRow()}": java.lang.NullPointerException at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:111) at org.primefaces.behavior.ajax.AjaxBehaviorListenerImpl.processAjaxBehavior(AjaxBehaviorListenerImpl.java:54) at org.primefaces.event.SelectEvent.processListener(SelectEvent.java:49)

khaled
  • 1
  • 2
  • Show us the error as well? – Ray Jun 02 '17 at 21:49
  • @Ray I have changed a lot in my code and am not able to bring back what I had, but I can explain what I am after, the datatable that I have it has the list of courses and when I select one from the page I want to get the selected row information so I have tried different ways that were mentioned on here but none of them worked for me – khaled Jun 02 '17 at 22:00
  • @Ray I have got what I had previously and here is the error that I got – khaled Jun 02 '17 at 22:48

0 Answers0