GWT 2.2 AsyncDataProvider / CellTable gotcha
Posted by David Chandler on March 2, 2011
I’ve been trying out CellTable in GWT 2.2 and found a potential gotcha. I created an AsyncDataProvider and attached the CellTable to it, but found that the table does not refresh properly unless you update BOTH row count and row data. If you call only updateRowData(), the CellTable will show the loading bar when there are zero rows, and will not remove rows when you delete them in the provider. The solution is simple: whenever you want to update a CellTable bound to an AsyncDataProvider, be sure to call both updateRowData() and updateRowCount(). Example code here:
public static class ListDataProvider extends AsyncDataProvider<ItemListProxy> { private Logger logger = Logger .getLogger(ListsActivity.ListDataProvider.class.getName()); private ListwidgetRequestFactory rf; public ListDataProvider(ListwidgetRequestFactory requestFactory) { this.rf = requestFactory; } @Override protected void onRangeChanged(HasData<ItemListProxy> display) { getData(); } private void getData() { logger.warning("getting data"); // To retrieve relations and value types, use .with() Request<List<ItemListProxy>> findAllReq = rf.itemListRequest() .listAll().with("owner"); // Receiver specifies return type findAllReq.fire(new Receiver<List<ItemListProxy>>() { @Override public void onSuccess(List<ItemListProxy> response) { updateRowCount(response.size(), true); updateRowData(0, response); } }); } }
tarek said
Hi,
I have the same problem with the table. Everything worked fine before i switched to the RequestFactory pattern. I used the Service/ServiceAsync pattern. Your fixed didnt worked for me. How do you attach the AsyncDataProvider to the table? Perhaps i make a fault there.
Thanks
Tarek
David Chandler said
Hi Tarek, to attach the table, call asyncDataProvider.addDataDisplay().
HTH, /dmc
sowdri said
hi David,
In the existing implementation of AysncDataProvider, even when the back button is pressed, we have to fetch the data from the server.
Will it be better to have a data structure List which will store the list of items already fetched from the server, such that we need not hit the server on hitting back button??
Thanks,
David Chandler said
Yes, it would be better. Listwidget is far from optimal. It’s mainly intended to demo the persistence layer.
Jason O'Connell said
Hello,
I was updating the SimplePager pageSize *after* updating the AsyncDataProvider rowcount and rowdata and my cell table was not displaying any data (just showing the loading bar)
I fixed this by updating the SimplePager before everything else.
So, if you need to update the SimplePager pageStart in your code, then the order that works for me now is:
SimplePager.setPageStart
AsyncDataProvider.updateRowCount
AsyncDataProvider.updateRowData
Jason O'Connell said
Actually, the order has to be:
AsyncDataProvider.updateRowCount
SimplePager.setPageStart
AsyncDataProvider.updateRowData
Koen Maes (@komasoftware) said
still valid in 2.4
sumit singhal said
hi i have a refresh button on my UI. so that wen i click it, table gets refreshed weather there is any addition or deletion of any row in database.
Anders K said
Also the issue in CellTree in GWT 2.5..
shashwat said
will this thing work in GWT 2.3 …and if you have a complete code please paste here..
My problem is ..I need to add a empty row in the cell table without repainting the celltable