问题
I have a CellList that I'm populating with an AsyncDataProvider:
@UiField(provided = true)
CellList<PlayerDataEntity> friendCellList;
@Inject
FriendListViewImpl(FriendListController controller) {
friendCellList = new CellList<PlayerDataEntity>(new PlayerCell());
initWidget(uiBinder.createAndBindUi(this));
// if we don't set the row data to empty before trying to get the real data,
// the empty list widget will never appear. But if we do set this,
// then the real data won't show up.
friendCellList.setRowData(Lists.<PlayerDataEntity>newArrayList());
new AsyncDataProvider<PlayerDataEntity>() {
@Override
protected void onRangeChanged(final HasData<PlayerDataEntity> display) {
rpcService.getPlayers(new AsyncCallback<List<PlayerDataEntity>>() {
@Override
public void onSuccess(List<PlayerDataEntity> result) {
display.setRowData(0, result);
}
});
}
}.addDataDisplay(friendCellList);
friendCellList.setEmptyListWidget(new Label("No friends found"));
}
If I don't initially set the row data to an empty list, then the empty list widget won't show up if the RPC service returns an empty list. However, if I do initially set the row data to the an empty list, and the RPC returns a non-empty list, that data won't show up in the widget.
I must be misunderstanding some aspect of the CellList's API. What am I doing wrong?
回答1:
If you know, that the total list (not just the list in the range) is empty, then you can set display.setRowCount(0), so the CellList will display "No friends found".
If your service always returns the entire list, this can be done easily like
public void onSuccess(List<PlayerDataEntity> result) {
display.setRowCount(result.size());
display.setRowData(0, result);
}
回答2:
Add the following line to the method:
@Override
public void onSuccess(List<PlayerDataEntity> result) {
display.setRowData(0, result);
((CellList<PlayerDataEntity>) display).redraw();
}
来源:https://stackoverflow.com/questions/10566483/trouble-with-celllist-empty-widget-and-asyncdataprovider