Hello,
I have a class "UserListPanel", which shows a CellTable of users. When such a panel is created it initially shows all existing users.
The set of users in the list may be changed by calling a method "setUserFilter", e. g. for selecting all users that match some criteria. Then, the list is reloaded by calling "CellTable.setVisibleRangeAndClearData".
There is a problem, when setUserFilter is called immediately after class instantiation:
UserListPanel p = new UserListPanel ();
RootLayoutPanel.get().add(p);
UserFilter f = new UserFilter (some criteria);
Window.alert ("Test");
p.setFilter (f); // has no effect, when Window.alert above is omitted
In this case, the call to setFilter has no effect, i. e. the list shows all users.
Note that within the AsyncDataProvider's onRangeChange a RPC call to the server is made in order to fetch data from the database.
I assume that there is a synchronization problem with the asynchronous calls and that they return in wrong order.
When I trace within "onRangeChanged" by opening a message box with "Window.alert", it works fine.
I also tried to put the reload method into a Scheduler.get().scheduleDeferred, without success.
So I need to ensure that all open RPC calls have returned before the call to setFilter is made.
How can I do that?
I would appreciate any hints.
Thanks
Magnus
public class UserListPanel extends AbsolutePanel
{
private CellTable<UserData> tbl;
private AsyncDataProvider<UserData> pvd;
private UserFilter flt; // filter users to display
public UserListPanel ()
{
...
initTable ();
}
private void initTable ()
{
...
tbl.setPageStart (0);
tbl.setPageSize (PAGESIZE);
pvd = new AsyncDataProvider<UserData>()
{
@Override
protected void onRangeChanged(HasData<UserData> display)
{
Range r = display.getVisibleRange();
int start = r.getStart() + 1;
int end = start + r.getLength() - 1;
loadUserDataList (start,end);
}
};
pvd.addDataDisplay(tbl);
Pager p = getPager ();
p.setDisplay(tbl);
p.setRangeLimited(true);
}
public void loadUserDataList (int i0,int i1)
{
// call asynchronous service, which calls loadUserDataList below
}
@Override
public void loadUserDataList (List<UserData> lst)
{
if (lst == null)
return;
Pager pgr = getPager ();
Range r = pgr.getDisplay().getVisibleRange();
int start = r.getStart();
pvd.updateRowData (start,lst);
}
public void setUserFilter (UserFilter flt)
{
this.flt = flt;
reload ();
}
public void reload ()
{
Range r = tbl.getVisibleRange();
tbl.setVisibleRangeAndClearData (r,true);
}
}