TurboManage

David Chandler's Journal of Java Web and Mobile Development

  • David M. Chandler


    Web app developer since 1994 and former Developer Advocate with Google now residing in Colorado. Besides tech, I enjoy landscape photography and share my work at ColoradoPhoto.gallery.

  • Subscribe

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 241 other followers

  • Sleepless Nights…

    March 2011
    S M T W T F S
    « Feb   Apr »
     12345
    6789101112
    13141516171819
    20212223242526
    2728293031  
  • Blog Stats

    • 865,600 hits

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);
				}
			});
		}
	}
Advertisements

10 Responses to “GWT 2.2 AsyncDataProvider / CellTable gotcha”

  1. 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

  2. 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,

  3. 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

  4. still valid in 2.4

  5. 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.

  6. Anders K said

    Also the issue in CellTree in GWT 2.5..

  7. 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

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: