DraggableRows throws IndexOutOfBound Exception

UI Components for JSF
Post Reply
mCd2023
Posts: 1
Joined: 27 Jul 2023, 15:07

27 Jul 2023, 15:36

I have a dataTable where the user can add documents and sort them as needed. When I drag the rows I get an IndexOutOfBoundException. I do not know why does this occurs and would like some help.


Controller.java

Code: Select all


    public void onRowReorder(ReorderEvent event) {  

        FacesContext.getCurrentInstance();
        int tindex = event.getToIndex();

        List<DocumentPrintCollection> printCollectionsSorted = getPrintCollectionsSorted();
        DocumentPrintCollection printCollection = printCollectionsSorted.get(tindex);
        int newSort = printCollection.getSort();

        printCollection.setSort(newSort);
        
    }
    
    public PrintCollection addPrintCollection() {
		PrintCollection newPrintCollection = null;
		int newSort = 1;

		for (PrintCollection printCollection : getPrintCollectionsSorted()) {
			if ((printCollection.isEmpty()) && (newPrintCollection == null)) {
				newPrintCollection = printCollection;
			}

			if (newSort <= printCollection.getSort()) {
				newSort = printCollection.getSort() + 1;
			}
		}

		if (newPrintCollection == null) {
			newPrintCollection = new PrintCollection(valuation);

			newPrintCollection.setSort(newSort++);
			modifyPrintCollection(newPrintCollection);
		
			this.printCollections.add(newPrintCollection);			
		}	
		
		return newPrintCollection;						
	}
viewDocument.xhtml

Code: Select all

<div id="#{cc.clientId}">
    <p:dataTable id="printcollection" 
                 value="#{cc.attrs.printCollection}"
                 var="collection" rowIndexVar="rowIndex" first="0"
                 reflow="true"
                 sortBy="#{printCollection.sort}"
                 sortOrder="ascending"
                 draggableRows="true"
                 widgetVar="printcollection">
        <p:ajax event="rowReorder" listener="#{cc.attrs.model.onRowReorder}" process="@this" update=":#{cc.clientId}:printcollection"/>
code to add document in viewDocument.xhtml

Code: Select all

<p:commandButton icon="fa fa-plus"
				 actionListener="#{cc.attrs.model.addPrintCollection()}"
				 process="tab_print_collection" update="tab_print_collection @(.vdp-autoupdate)"
				 disabled="#{cc.attrs.readOnly}"/>
					
StackTrace:

Code: Select all

Message: toIndex = 2
StackTrace: java.lang.IndexOutOfBoundsException: toIndex = 2
at java.base/java.util.AbstractList.subListRangeCheck(AbstractList.java:507)
at java.base/java.util.ArrayList.subList(ArrayList.java:1108)
at org.primefaces.component.datatable.feature.DraggableRowsFeature.decode(DraggableRowsFeature.java:74)
at org.primefaces.component.datatable.DataTableRenderer.decode(DataTableRenderer.java:72)
at javax.faces.component.UIComponentBase.decode(UIComponentBase.java:509)
at org.primefaces.component.api.UIData.processDecodes(UIData.java:117)
at com.sun.faces.context.PartialViewContextImpl$PhaseAwareVisitCallback.visit(PartialViewContextImpl.java:606)
at com.sun.faces.component.visit.PartialVisitContext.invokeVisitCallback(PartialVisitContext.java:159)
at org.primefaces.component.api.UIData.visitTree(UIData.java:691)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1468)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1468)
at javax.faces.component.UINamingContainer.visitTree(UINamingContainer.java:150)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1468)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1468)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1468)
at org.primefaces.component.api.UITabPanel.visitTree(UITabPanel.java:939)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1468)
at javax.faces.component.UIForm.visitTree(UIForm.java:355)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1468)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1468)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1468)
at com.sun.faces.context.PartialViewContextImpl.processComponents(PartialViewContextImpl.java:400)
at com.sun.faces.context.PartialViewContextImpl.processPartial(PartialViewContextImpl.java:261)
at org.primefaces.context.PrimePartialViewContext.processPartial(PrimePartialViewContext.java:65)
at javax.faces.component.UIViewRoot.processDecodes(UIViewRoot.java:1008)
at com.sun.faces.lifecycle.ApplyRequestValuesPhase.execute(ApplyRequestValuesPhase.java:55)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:76)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:177)
at javax.faces.webapp.FacesServlet.executeLifecyle(FacesServlet.java:707)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:451)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1637)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:259)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:167)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:757)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:577)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:158)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:372)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:239)
at com.sun.enterprise.v3.services.impl.ContainerMapper$HttpHandlerCallable.call(ContainerMapper.java:520)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:217)
at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:182)
at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:156)
at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:201)
at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:95)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:260)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:177)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:109)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:88)
at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:53)
at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:524)
at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:89)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:94)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:33)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:114)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:569)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:549)
at java.base/java.lang.Thread.run(Thread.java:833)
If you need any more information, please do let me know. Thanks!
(P.S I am new to Primefaces)

jepsar
Posts: 166
Joined: 03 Sep 2014, 11:41
Location: NL / BE
Contact:

28 Jul 2023, 18:16

As stated on StackOverflow: please create a runnable reproducer, using https://github.com/primefaces/primefaces-test and the latest version of PF.
PrimeFaces Developer | PrimeFaces Extensions Developer
GitHub: https://github.com/jepsar
Spotify: 90s Rave, Acid, Trance, House

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: Google [Bot] and 58 guests