Lazy dataTable and editable row

UI Components for JSF
Post Reply
yanmania
Posts: 6
Joined: 17 Jan 2013, 16:03

30 Jul 2015, 10:08

Hello,

I am using primefaces 5.2 with JBoss AS 7.

I would like to use an editable row within a lazy dataTable. My obects are in the scope request. Here is my xhtml :

Code: Select all

<h:form>
   <p:dataTable id="myTable" value="#{myList}" var="_list"	lazy="true" rows="10" paginator="true" editable="true">
      <p:ajax event="rowEdit" listener="#{myController.onRowEdit}" />
      <p:ajax event="rowEditCancel" listener="#{myController.onRowCancel}" />
      ...
      <p:column>
         <p:rowEditor />
      </p:column>
   </p:dataTable>
</h:form>
For the server side I extend a simple LazyDataModel and overwrite acces methods getRowData(String rowKeyVar) and getId(Object object) like that :

Code: Select all

public class MyLazyDataModel extends LazyDataModel<MyObject> {
        ...
        @Override
	public MyObject getRowData(String rowKey) {
		 return em.find(MyObject.class, new Integer(rowKey));
	 }

	 @Override
 	public Object getRowKey(MyObject myObject{
		 return myObject.getId();
	 }
	
	@Override
 	public List<MyObject> load(int first, int pageSize, String sortField, SortOrder sortOrder, Map<String, Object> filters) {...}
}
I always get a NullPointerException when I try to validate or cancel my input. When I debug my code I notice that my acces method are never used (while these methods are used for a row selection) and instead primefaces use getRowData() of superClass (LazyDataModel) and this is why I get this NullPointerException.
So I went two level upper on the stack trace and I notice a big diference between row selection and row edition to explain "the difference of behavior" :

Code: Select all

public class DataTable extends UIData implements org.primefac... {
        ...
        @Override
	public void queueEvent(FacesEvent event) {
		...
                // Working :
                if(eventName.equals("rowSelect")||eventName.equals("rowSelectRadio")||eventName.equals("contextMenu")
                    ||eventName.equals("rowSelectCheckbox")||eventName.equals("rowDblselect")) {
                String rowKey = params.get(clientId + "_instantSelectedRowKey");
                wrapperEvent = new SelectEvent(this, behaviorEvent.getBehavior(), this.getRowData(rowKey)); 
            }
            else if(eventName.equals("rowUnselect")||eventName.equals("rowUnselectCheckbox")) {
                String rowKey = params.get(clientId + "_instantUnselectedRowKey");
                wrapperEvent = new UnselectEvent(this, behaviorEvent.getBehavior(), this.getRowData(rowKey));
            }
                ...
             // Not working ?
             else if(eventName.equals("rowEdit")||eventName.equals("rowEditCancel")||eventName.equals("rowEditInit")) {
                int rowIndex = Integer.parseInt(params.get(clientId + "_rowEditIndex"));
                setRowIndex(rowIndex);
                wrapperEvent = new RowEditEvent(this, behaviorEvent.getBehavior(), this.getRowData());
            }
	}

	...
}
With lazyDataTable, data must be initialize and when primefaces try to acces data from getRowData() using index instead of rowKey, "index == -1" and "data = null", Is this a bug ? Is there a workaround to make my code works ?
Primefaces 5.2
JBoss 7.1.1.Final or Wildfly 8.2.1.Final

yanmania
Posts: 6
Joined: 17 Jan 2013, 16:03

31 Jul 2015, 17:40

If I change the requestScope to sessionScope or ViewScope (omnifaces) the NPE disappear. So I think that behaviour confirms this is a bug : data from LazyDataModel is not initialize correctly for the RowEdition events.

I have just opened this issue : https://github.com/primefaces/primefaces/issues/593
Primefaces 5.2
JBoss 7.1.1.Final or Wildfly 8.2.1.Final

kukeltje
Expert Member
Posts: 9605
Joined: 17 Jun 2010, 13:34
Location: Netherlands

11 Aug 2015, 16:14

it is good to post a Stacktrace... when an NPE happens.

And O/T: Do you use a second level cache? I hope so, otherwise the 'em.find' in the getRowData(...) can become a performancekiller

yanmania
Posts: 6
Joined: 17 Jan 2013, 16:03

26 Aug 2015, 14:24

Thank you for the performance tip.

I finally use a dataTable without lazy. The edition works perfectly in this mode. I think I do not need a lazy datamodel for this table. I hope this bug will be corrected for the next releases.
Primefaces 5.2
JBoss 7.1.1.Final or Wildfly 8.2.1.Final

Pollum
Posts: 6
Joined: 16 Nov 2015, 16:22

11 Apr 2016, 14:18

Hi,

I have the same problem. When using @RequestScoped CDI bean I get a NullPointerException with lazydatamodel and editable datatable. My solution is a @SessionScoped bean, but it would be nice to have this potential bug fixed.

Here is my stacktrace:

Code: Select all

java.lang.NullPointerException: null
	at org.primefaces.model.LazyDataModel.getRowData(LazyDataModel.java:56) ~[primefaces-5.3.jar:5.3]
	at test.EntityDataModel$Proxy$_$$_WeldClientProxy.getRowData(Unknown Source) ~[EntityDataModel.class:na]
	at javax.faces.component.UIData.getRowData(UIData.java:371) ~[javax.faces.jar:2.2.0]
	at org.primefaces.component.datatable.DataTable.queueEvent(DataTable.java:807) ~[primefaces-5.3.jar:5.3]
	at org.primefaces.behavior.ajax.AjaxBehaviorRenderer.decode(AjaxBehaviorRenderer.java:47) ~[primefaces-5.3.jar:5.3]
	at javax.faces.component.behavior.ClientBehaviorBase.decode(ClientBehaviorBase.java:132) ~[javax.faces.jar:2.2.0]
	at org.primefaces.renderkit.CoreRenderer.decodeBehaviors(CoreRenderer.java:530) ~[primefaces-5.3.jar:5.3]
	at org.primefaces.component.datatable.DataTableRenderer.decode(DataTableRenderer.java:66) ~[primefaces-5.3.jar:5.3]
	at javax.faces.component.UIComponentBase.decode(UIComponentBase.java:836) ~[javax.faces.jar:2.2.0]
	at org.primefaces.component.api.UIData.processDecodes(UIData.java:282) ~[primefaces-5.3.jar:5.3]
	at com.sun.faces.context.PartialViewContextImpl$PhaseAwareVisitCallback.visit(PartialViewContextImpl.java:550) ~[javax.faces.jar:2.2.0]
	at com.sun.faces.component.visit.PartialVisitContext.invokeVisitCallback(PartialVisitContext.java:183) ~[javax.faces.jar:2.2.0]
	at org.primefaces.component.api.UIData.visitTree(UIData.java:822) ~[primefaces-5.3.jar:5.3]
	at javax.faces.component.UIComponent.visitTree(UIComponent.java:1700) ~[javax.faces.jar:2.2.0]
	at javax.faces.component.UIComponent.visitTree(UIComponent.java:1700) ~[javax.faces.jar:2.2.0]
	at org.primefaces.component.api.UITabPanel.visitTree(UITabPanel.java:920) ~[primefaces-5.3.jar:5.3]
	at javax.faces.component.UIComponent.visitTree(UIComponent.java:1700) ~[javax.faces.jar:2.2.0]
	at javax.faces.component.UIForm.visitTree(UIForm.java:371) ~[javax.faces.jar:2.2.0]
	at javax.faces.component.UIComponent.visitTree(UIComponent.java:1700) ~[javax.faces.jar:2.2.0]
	at javax.faces.component.UIComponent.visitTree(UIComponent.java:1700) ~[javax.faces.jar:2.2.0]
	at javax.faces.component.UIComponent.visitTree(UIComponent.java:1700) ~[javax.faces.jar:2.2.0]
	at javax.faces.component.UIComponent.visitTree(UIComponent.java:1700) ~[javax.faces.jar:2.2.0]
	at javax.faces.component.UIComponent.visitTree(UIComponent.java:1700) ~[javax.faces.jar:2.2.0]
	at javax.faces.component.UIComponent.visitTree(UIComponent.java:1700) ~[javax.faces.jar:2.2.0]
	at com.sun.faces.context.PartialViewContextImpl.processComponents(PartialViewContextImpl.java:399) ~[javax.faces.jar:2.2.0]
	at com.sun.faces.context.PartialViewContextImpl.processPartial(PartialViewContextImpl.java:263) ~[javax.faces.jar:2.2.0]
	at org.primefaces.context.PrimePartialViewContext.processPartial(PrimePartialViewContext.java:60) ~[primefaces-5.3.jar:5.3]
	at javax.faces.context.PartialViewContextWrapper.processPartial(PartialViewContextWrapper.java:219) ~[javax.faces.jar:2.2.0]
	at javax.faces.component.UIViewRoot.processDecodes(UIViewRoot.java:927) ~[javax.faces.jar:2.2.0]
	at com.sun.faces.lifecycle.ApplyRequestValuesPhase.execute(ApplyRequestValuesPhase.java:78) ~[javax.faces.jar:2.2.0]
	at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101) ~[javax.faces.jar:2.2.0]
	at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198) [javax.faces.jar:2.2.0]
	at javax.faces.webapp.FacesServlet.service(FacesServlet.java:646) [javax.faces.jar:2.2.0]
	at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682) [web-core.jar:na]
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:344) [web-core.jar:na]
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214) [web-core.jar:na]
	at test.MyFilter.doFilter(MyFilter.java:52) [MyFilter.class:na]
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256) [web-core.jar:na]
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214) [web-core.jar:na]
	at net.sourceforge.spnego.SpnegoHttpFilter.doFilter(SpnegoHttpFilter.java:250) [spnego.jar:na]
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256) [web-core.jar:na]
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214) [web-core.jar:na]
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:316) [web-core.jar:na]
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160) [web-core.jar:na]
	at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:734) [web-core.jar:na]
	at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673) [web-core.jar:na]
	at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99) [web-glue.jar:na]
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:174) [web-core.jar:na]
	at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:357) [web-core.jar:na]
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:260) [web-core.jar:na]
	at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:188) [kernel.jar:na]
	at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:191) [nucleus-grizzly-all.jar:na]
	at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:168) [nucleus-grizzly-all.jar:na]
	at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:189) [nucleus-grizzly-all.jar:na]
	at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119) [nucleus-grizzly-all.jar:na]
	at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:288) [nucleus-grizzly-all.jar:na]
	at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:206) [nucleus-grizzly-all.jar:na]
	at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:136) [nucleus-grizzly-all.jar:na]
	at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:114) [nucleus-grizzly-all.jar:na]
	at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77) [nucleus-grizzly-all.jar:na]
	at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:838) [nucleus-grizzly-all.jar:na]
	at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:113) [nucleus-grizzly-all.jar:na]
	at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:115) [nucleus-grizzly-all.jar:na]
	at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:55) [nucleus-grizzly-all.jar:na]
	at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:135) [nucleus-grizzly-all.jar:na]
	at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:564) [nucleus-grizzly-all.jar:na]
	at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:544) [nucleus-grizzly-all.jar:na]
	at java.lang.Thread.run(Thread.java:745) [na:1.7.0_67]
Primefaces 5.3 | JSF 2.2 Mojarra | Glassfish 4.0
Primefaces 6.0 | JSF 2.2 Mojarra | Glassfish 4.0

kukeltje
Expert Member
Posts: 9605
Joined: 17 Jun 2010, 13:34
Location: Netherlands

12 Apr 2016, 09:35

I always use @ViewScoped for things like this (not session scoped). The 'downside' of keeping some information in the server compared to using requestscoped beans is negligable I think.

But if it really is a bug (can you create/find a fix?) then it should be corrected. Please add some comment to the 'issue' that you have added additional information in the forum post

Post Reply

Return to “PrimeFaces”

  • Information