Reputation: 21
I have celltable and a simplepager. I am making async calls to the server to return data as a list.
AsyncDataProvider<Entry> provider = new AsyncDataProvider<Entry>() {
@Override
protected void onRangeChanged(HasData<Entry> display) {
final int start = display.getVisibleRange().getStart();
int length = display.getVisibleRange().getLength();
AsyncCallback<List<Entry>> callback = new AsyncCallback<List<Entry>>() {
@Override
public void onFailure(Throwable caught) {
Window.alert(caught.getMessage());
}
@Override
public void onSuccess(List<Entry> result) {
updateRowData(start, result);
}
};
// The remote service that should be implemented
rpcService.fetchEntries(start, length, callback);
}
};
On the server side ...
public List<Entry> fetchEntries(int start, int length) {
if (start > ENTRIES.size())
return new ArrayList<Entry>();
int end = start + length > ENTRIES.size() ? ENTRIES.size() : start
+ length;
ArrayList<Entry> sublist = new ArrayList<Entry>(
(List<Entry>) ENTRIES.subList(start, end));
return sublist;
}
The problem is that I don't know the size of the dataset returned by the aync call. So I cannot set the updateRowCount. So now the next button is always active even though the dataset has only 24 fields. Any ideas ?
Upvotes: 1
Views: 1080
Reputation: 11625
How about modifying your RPC service to return a flag as well:
class FetchEntriesResult{
private int totalNumberOfEntries;
private List<Entry> entries;
//getters,setters, constructor etc...
}
And your service method becomes something like:
public FetchEntriesResult fetchEntries(int start, int length) {
if (start > ENTRIES.size())
return new ArrayList<Entry>();
int end = start + length > ENTRIES.size() ? ENTRIES.size() : start
+ length;
ArrayList<Entry> sublist = new ArrayList<Entry>(
(List<Entry>) ENTRIES.subList(start, end));
return new FetchEntriesResult(sublist,ENTRIES.size());
}
Now you can use the FetchEntriesResult.getTotalNumberOfEntries()
on the client.
Upvotes: 1