Primefaces datatable onRowSelect method causing nullpointer exception

吃可爱长大的小学妹 提交于 2019-12-11 17:47:08

问题


I am using Hibernate 4, Spring 3 and JSF 2.0 with Weblogic 10.3.6 as server. I am loading my datatable using lazy loading.

JSF Page

  <p:dataTable id="dataTable" var="req" lazy="true" value="#{emp.lazyModel}"
                paginator="true" rows="10" 
                             selection="#{emp.selectedRequest}"
                            selectionMode="single">                         
          <p:ajax event="rowSelect" listener="#{emp.onRowSelect}" />  

When I select a row in a datatable I am getting null pointer exception in onRowSelect method.

ManagedBean

public void onRowSelect(SelectEvent event) {
        try {

            this.setRequestNo(event.getObject().toString());            

        } catch (Exception e) {
            e.printStackTrace();                
        }

    }

In LazyEmpDataModel I have the following methods

@Override
    public void setRowIndex(final int rowIndex) {
        if (rowIndex == -1 || getPageSize() == 0) {
            super.setRowIndex(-1);
        } else {
            super.setRowIndex(rowIndex % getPageSize());
        }
    }

    @Override
    public Object getRowKey(Employees emp) {
        return request.getRequestNo();
    }

@Override
    public Employees getRowData(String rowKey) {
        for (Employees emp : requestList) {
            if (emp.getEmpNo().equals(rowKey))
                return emp;
        }

        return null;
    }

Full stackexception

java.lang.NullPointerException
    at net.test.managed.bean.RequestManagedBean.onRowSelect(RequestManagedBean.java:134)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at com.sun.el.parser.AstValue.invoke(AstValue.java:187)
    at com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:297)
    at org.primefaces.component.behavior.ajax.AjaxBehaviorListenerImpl.processAjaxBehavior(AjaxBehaviorListenerImpl.java:52)
    at org.primefaces.event.SelectEvent.processListener(SelectEvent.java:40)
    at javax.faces.component.behavior.BehaviorBase.broadcast(BehaviorBase.java:106)
    at javax.faces.component.UIComponentBase.broadcast(UIComponentBase.java:760)
    at javax.faces.component.UIData.broadcast(UIData.java:1071)
    at javax.faces.component.UIData.broadcast(UIData.java:1093)
    at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:794)
    at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1259)
    at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
    at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:593)
    at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227)
    at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125)
    at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:301)
    at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:26)
    at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
    at weblogic.servlet.internal.RequestEventsFilter.doFilter(RequestEventsFilter.java:27)
    at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
    at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.wrapRun(WebAppServletContext.java:3730)
    at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3696)
    at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
    at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:120)
    at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2273)
    at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2179)
    at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1490)
    at weblogic.work.ExecuteThread.execute(ExecuteThread.java:256)
    at weblogic.work.ExecuteThread.run(ExecuteThread.java:221)

回答1:


INMO its something with your view scope bean , try making it session... if session will help look for a way to work properly with CDI View bean

Maybe its being invalidated for some reason... Add a post constructor to your bean with print lines and see if its indeed being reconstructed upon pagination / row selection



来源:https://stackoverflow.com/questions/14040049/primefaces-datatable-onrowselect-method-causing-nullpointer-exception

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!