我有celltable和simplepager。我正在对服务器进行异步调用以将数据作为列表返回。
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);
}
};
在服务器端......
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;
}
问题是我不知道aync调用返回的数据集的大小。所以我无法设置updateRowCount。所以现在,即使数据集只有24个字段,下一个按钮也始终处于活动状态。有什么想法吗?
答案 0 :(得分:1)
如何修改RPC服务以返回标志:
class FetchEntriesResult{
private int totalNumberOfEntries;
private List<Entry> entries;
//getters,setters, constructor etc...
}
您的服务方法就像:
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());
}
现在您可以在客户端上使用FetchEntriesResult.getTotalNumberOfEntries()
。