Don't forget CachedTableModel.clearCache()

6 views
Skip to first unread message

Geraldo Lopes

unread,
Nov 22, 2008, 8:00:50 PM11/22/08
to Google Web Toolkit Contributors
Hi,

I'm making a crud application that uses PagingScrollTable. It consists
of a paging grid and a form that reflects the current selected row. I
use the form to make query by example, so I start with a group of
values and depending on the search I need to populate the grid with
completely different set of values. After the user click the search
button I was trying to reload the values with :

myPagingGrid.gotoPage(0, true); // true to force reload.

I was getting strange results, with values of the last search being
mixed with the ones of the current search.

My mistake was I'm using CachedTableModel, that encapsulate my real
table mode and it was keeping values from the last search around.

final CachedTableModel<Cliente> cachedTableModel = new
CachedTableModel<Cliente>(tableModel);

So cachedTableModel.clearCache() before myPagingGrid.gotoPage(0, true)
solved the problem.

Just wondering:

CachedTableModel extends MutableTableModel which extends TableModel,
and PagingScrollTable points to TableModel, so I can't invoke clear
cache via PagingScrollTable. Instead I have to pass a instance to
PagingScrollTable and CachedTableModel to be able to:

cachedTableModel.clearCache();
myPagingGrid.gotoPage(0, true);

If TableModel had an abstract clearCache method, I could make:

myPagingGrid.getTableModel().clearCache();
myPagingGrid.gotoPage(0, true);

That would be more clean imho.

Thanks for the marvelous work you are doing.

Geraldo Lopes




Isaac Truett

unread,
Nov 23, 2008, 10:06:32 AM11/23/08
to Google-Web-Tool...@googlegroups.com
> If TableModel had an abstract clearCache method, I could make:
>
> myPagingGrid.getTableModel().clearCache();
> myPagingGrid.gotoPage(0, true);
>
> That would be more clean imho.

But it wouldn't, you see, because not all TableModels have caching.
You're trying to move a method higher up the inheritance chain where
it doesn't belong. The fact that your PST uses a caching TableModel is
an implementation detail of your application. You should extend or
encapsulate PST and your TableModel and provide/override a method in
that new object that handles clearing the cache before refreshing the
page.
Reply all
Reply to author
Forward
0 new messages