在primefaces数据表celleditevent上添加一个新行,在getrowindex上给出java.lang.NullPointerException

时间:2014-09-30 14:16:39

标签: hibernate jsf primefaces spring-data-jpa

我在Primefaces Datatable上保存了员工的详细信息。我在事件getrowindex上得到了nullpointerexception 我使用的是primefaces 4.0 netbeans 7.4,jpa hibernate和spring 3.2.3。

employee.xhtml

<p:remoteCommand update="newEmployee" name="newRow" process="@form"/> 
                    <p:dataTable value="${employeeController.newList()}"
                                 var="emp" id="newEmployee"
                                 editMode="cell"  
                                 scrollable="true"  
                                 editable="true"  
                                 scrollHeight="150"> 

                        <p:ajax event="cellEdit" listener="${employeeController.addRow(event)}" 
                                oncomplete="newRow()" process="@this"/>
                        <p:column headerText="Name">
                            <p:cellEditor>
                                <f:facet name="output">
                                    <p:outputLabel value="#{emp.name}"/>
                                </f:facet>
                                <f:facet name="input">
                                     <p:inputText value="${emp.name}"/>  
                                </f:facet>
                            </p:cellEditor>
                        </p:column>
                        </dataTable>

employeeController.java

public List<Employee> addRow(CellEditEvent evnt) { 
    List<Employee> bfList = new ArrayList();
    int r = evnt.getRowIndex();
    bfList.add(employee);   
    if (bfList.size() == (r + 1) || bfList.size() == 1) { 
        bfList.add(new Employee());
    } 
    return bfList;
}

&GT;

 SEVERE:   [http-listener-1(5)] INFO com.emp.controller.employeeController - evt
WARNING:   StandardWrapperValve[Dispatcher]: Servlet.service() for servlet Dispatcher threw exception
java.lang.NullPointerException
    at com.emp.controller.employeeController.addRow(employeeController.java:94)
    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 javax.el.ELUtil.invokeMethod(ELUtil.java:326)
    at javax.el.BeanELResolver.invoke(BeanELResolver.java:536)
    at javax.el.CompositeELResolver.invoke(CompositeELResolver.java:256)
    at com.sun.el.parser.AstValue.invoke(AstValue.java:269)
    at com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:304)
    at org.jboss.weld.util.el.ForwardingMethodExpression.invoke(ForwardingMethodExpression.java:40)
    at org.jboss.weld.el.WeldMethodExpression.invoke(WeldMethodExpression.java:50)
    at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
    at org.primefaces.component.behavior.ajax.AjaxBehaviorListenerImpl.processAjaxBehavior(AjaxBehaviorListenerImpl.java:53)
    at org.primefaces.event.CellEditEvent.processListener(CellEditEvent.java:55)
    at javax.faces.component.behavior.BehaviorBase.broadcast(BehaviorBase.java:106)
    at javax.faces.component.UIComponentBase.broadcast(UIComponentBase.java:809)
    at javax.faces.component.UIData.broadcast(UIData.java:1086)
    at javax.faces.component.UIData.broadcast(UIData.java:1108)
    at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:790)
    at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1282)
    at org.springframework.faces.webflow.FlowLifecycle.invokePhase(FlowLifecycle.java:97)
    at org.springframework.faces.webflow.FlowLifecycle.execute(FlowLifecycle.java:69)
    at org.springframework.faces.webflow.JsfView.processUserEvent(JsfView.java:115)
    at org.springframework.webflow.engine.ViewState.handleEvent(ViewState.java:225)
    at org.springframework.webflow.engine.ViewState.resume(ViewState.java:195)
    at org.springframework.webflow.engine.Flow.resume(Flow.java:537)
    at org.springframework.webflow.engine.impl.FlowExecutionImpl.resume(FlowExecutionImpl.java:259)
    at org.springframework.webflow.executor.FlowExecutorImpl.resumeExecution(FlowExecutorImpl.java:169)
    at org.springframework.webflow.mvc.servlet.FlowHandlerAdapter.handle(FlowHandlerAdapter.java:227)
    at org.springframework.faces.webflow.JsfFlowHandlerAdapter.handle(JsfFlowHandlerAdapter.java:46)
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:925)
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856)
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:920)
    at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:827)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
    at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:801)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
    at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:318)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160)
    at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:734)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673)
    at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:174)
    at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:357)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:260)
    at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:188)
    at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:191)
    at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:168)
    at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:189)
    at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:288)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:206)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:136)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:114)
    at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
    at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:838)
    at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:113)
    at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:115)
    at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:55)
    at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:135)
    at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:564)
    at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:544)
    at java.lang.Thread.run(Thread.java:722)

1 个答案:

答案 0 :(得分:1)

在employee.xhtml中:

<p:ajax event="cellEdit" listener="${employeeController.addRow}" oncomplete="newRow()" process="@this"/>

代替

<p:ajax event="cellEdit" listener="${employeeController.addRow(event)}" oncomplete="newRow()" process="@this"/>

listener="${employeeController.addRow}代替listener="${employeeController.addRow(event)}"