Updating a DataTable with sorting or filtering

UI Components for JSF
Post Reply
csyperski
Posts: 103
Joined: 16 Apr 2010, 14:36

31 Aug 2010, 14:03

This is an issue I have seen for a while, but have just lived with. Is it possible, to update with PPR a DataTable that has been either sorted or filtered? It seems like everything works fine until you sort or filter the table. When attempting to update, it seems for me that the page/table isn't updated.

Here is a quick and dirty example:

Code: Select all

.....
<h:form  prependId="false" >
<h:inputText style="margin-bottom: 5px;" value="#{detention.studentHistorySearch}" required="true">
<f:validateLength maximum="100" minimum="1" />
</h:inputText>
<p:commandButton value="#{msg.tardyHistorySearchBtn}" action="#{detention.loadStudentHistory}" update="frmHistTable" />
</h:form>
......
<h:form id="frmHistTable" prependId="false">
<p:dataTable  lazy="true" selection="#{detention.studentHistoryDetails}" onselectComplete="dlgStudHist.show()" selectionMode="single" id="studhistory" update="growl dialogStudHist" dynamic="true" var="hist" value="#{detention.studentHistory}" paginator="true" rows="30">
<p:column sortBy="#{d.detention.opened}" >
<f:facet name="header">
<h:outputText value="#{msg.tardyOutStandOpened}" />
</f:facet>
<h:panelGroup  rendered="#{hist.detention.opened}">
<h:graphicImage id="openedStateHist" url="/public/images/viewed.png" />
<p:tooltip for="openedStateHist" style="myStyle" value="#{msg.tipOpen} #{hist.detention.openedTime}" showEffect="slide" hideEffect="slide" showEffectLength="500"/>
</h:panelGroup>
</p:column>
<p:column filterBy="#{hist.student.studentNumber}" sortBy="#{hist.student.studentNumber}" >
<f:facet name="header">
 <h:outputText value="#{msg.tardyOutStandStudNumber}" />
 </f:facet>
<h:outputText value="#{hist.student.studentNumber}" />
</p:column>
......
</p:dataTable>
</h:form>
In this example, if I click on the p:commandButton without filtering all works well, it I filter or sort by the second p:column, then click the p:commandButton, my dataset is updated in the backing bean, but never gets pushed to the display. I don't get any JS errors or anything visible on the client side, nor the server side.

This bug seems present on 2.0.2 and 2.1. I am testing on tomcat6 using firefox and chrome on Ubuntu 10.04 64bit.

Thanks for any insight you can offer and that to the Primefaces Team for making a great product!

cagatay.civici
Prime
Posts: 18616
Joined: 05 Jan 2009, 00:21
Location: Cybertron
Contact:

31 Aug 2010, 14:40

I think I know why this happens, can you try with our brand new datatable of 2.2.M1-SNAPSHOT. If I'm right, if you update after sort, you can get new data but if you update after filter, it will display the old data. We should fix these by next weeks 2.2.M1 release.

csyperski
Posts: 103
Joined: 16 Apr 2010, 14:36

31 Aug 2010, 14:59

That sounds great! I will give it a try with the new rev.

cagatay.civici
Prime
Posts: 18616
Joined: 05 Jan 2009, 00:21
Location: Cybertron
Contact:

01 Sep 2010, 03:51

Thanks, we're thinking about a solution for this particular case.

cj91
Posts: 96
Joined: 04 Feb 2010, 00:07

01 Sep 2010, 03:55

This sounds like the issue I posted about here: http://primefaces.prime.com.tr/forum/vi ... 130#p19130

It's fixed in 2.2 for Chrome/Safari, but pushing updates to a 2.2 Datatable doesn't work in IE or Firefox. Can't wait for the 2.2 release, the new features look excellent

cj91
Posts: 96
Joined: 04 Feb 2010, 00:07

02 Sep 2010, 23:13

Optimus, this is a huge impact for my current work. Our project goes to Quality Control before PrimeFaces2.2 will be released, so we can't wait that long... I'm attempting to find the root cause of the issue; if you have a hunch of what I should look for, I'd appreciate any hints.

cj91
Posts: 96
Joined: 04 Feb 2010, 00:07

02 Sep 2010, 23:34

I noticed UIData.setValue will reset the DataModel. Primefaces 2.2 doesn't ever call setValue, so I removed the calls in 2.1 to avoid resetting the dataModel.

The attached patch seems to fix the problem, but I don't know if it's the 'right way' to solve the problem.

Patch:

Code: Select all

Index: DataTableRenderer.java
===================================================================
--- DataTableRenderer.java	(revision 83316)
+++ DataTableRenderer.java	(working copy)
@@ -62,6 +62,7 @@
 		} else if(dataTable.isSelectionEnabled()) {
 			decodeSelection(facesContext, dataTable);
 		}
+		
 	}
 	
 	/**
@@ -91,7 +92,6 @@
 		
 		List list = (List) dataTable.getValue();
 		Collections.sort(list, new BeanPropertyComparator(findSortColumm(dataTable, sortKey), dataTable.getVar(), sortDir));
-		dataTable.setValue(list);
 		
 		//Reset paginator
 		dataTable.setFirst(0);
@@ -102,8 +102,8 @@
 	protected void decodeAjaxFilterRequest(FacesContext facesContext, DataTable dataTable) {
 		Map<String,String> params = facesContext.getExternalContext().getRequestParameterMap();
 		Map<String,ValueExpression> filterMap = dataTable.getFilterMap();
-		List filteredData = new ArrayList();
-		dataTable.setValue(null);	//Always work with user data
+		List filteredData = (List) dataTable.getValue();
+		filteredData.clear();
 		
 		for(int i = 0; i < dataTable.getRowCount(); i++) {
 			dataTable.setRowIndex(i);
@@ -131,8 +131,6 @@
 		
 		dataTable.setRowIndex(-1);	//cleanup
 		
-		dataTable.setValue(filteredData);
-		
 		//Reset paginator
 		dataTable.setFirst(0);
 		dataTable.setPage(1);


dhaalves
Posts: 13
Joined: 27 Apr 2010, 16:54
Location: Brazil

04 Oct 2010, 17:18

Hello,

I kinda confused about this issue, if fact i dont know if my problemn is the same as this.

My problemn happens just after filtering, then when i try to update the datatable it´s display empty like on the img above.

Image

Here is my post
http://primefaces.prime.com.tr/forum/vi ... ble#p20657
PrimeFaces 3.0-SNAPSHOT, Mojarra 2.0.4, Glassfish 3.0.1/GAE

filevanderl
Posts: 5
Joined: 12 Aug 2010, 11:00

11 Oct 2010, 17:00

I have the same problem. I am inserting and deleting rows from table (with p:commandButton and update table with ajax). Everything works fine on dataTable dynamic="true". After filtering or sorting on dataTable it stop working. Everything looks fine but getter for dataTable value is not called. I refresh entire page and everything works again.

tested on primefaces 2.2.M1 and 2.2.RC1-SNAPSHOT mojarra 2.0.3

anan
Posts: 5
Joined: 17 May 2010, 06:37

19 Oct 2010, 07:15

Hi, I have the same problem. DataTable still shows the item I already deleted if I have something in the filter box. If the filter box is empty, everything works fine.

There seems to be no fix at this point but I have a work around by calling the filter() method using oncomplete property. For example, my delete button look like this
<p:commandLink value="delete" action="#{row.remove}" immediate="true" update="refresh:mainTable" oncomplete="widget_refresh_mainTable.filter()"/>

I haven't tried this with sort but I guess it would work the same way.
Good luck
Anan

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 43 guests