Hi everybody,
I have a short but painful question: Where is the right place to initialize
my AsyncDataProvider?
Story so far:
In my Controller class I have my AsyncDataProvider as reference and the
search method where I built the asynchronous callback and process my data,
looks like this.
private final ClientServiceAsync service = GWT.create(ClientService.class);
private AsyncDataProvider<Model> provider;
private List<Model> dataList = new ArrayList<Model>();
// other stuff here...
void search(final TO_Search pSearchCriteria) {
// Associate an async data provider to the table
provider = new AsyncDataProvider<Model>() {
@Override
protected void onRangeChanged(HasData<Model> display) {
final int start = display.getVisibleRange().getStart();
int length = display.getVisibleRange().getLength();
// Get the ColumnSortInfo from the table.
final ColumnSortList sortList = view.cellTable.getColumnSortList();
final ColumnSortInfo sortInfo = sortList.get(0);
final String dataStoreName =
sortInfo.getColumn().getDataStoreName();
final boolean isAscending = sortInfo.isAscending();
AsyncCallback<TO_Result> callback = new AsyncCallback<TO_Result>() {
@Override
public void onFailure(Throwable caught) {
Window.alert(caught.getMessage());
}
@Override
public void onSuccess(TO_Result data) {
if (!GWT.isProdMode()) {
GWT.log(this.getClass() + ": Remote Procedure Call -
Success");
GWT.log(this.getClass() + ": No. of results = " +
data.getCount());
}
if (data.getCount() != 0) {
dataList.addAll(data.getResults());
updateRowData(start, data.getResults());
updateRowCount(data.getCount(), true);
if (data.isGoToFirstPage()) {
view.setPagerFirstPage();
}
} else {
dataList.clear();
updateRowData(start, dataList);
updateRowCount(data.getCount(), true);
view.simplePopup.setWidget(new
HTML(CONSTANTS.noSearchResults()));
}
}
};
service.search(searchCriteria, start, length, dataStoreName,
isAscending, callback);
}
};
} // end search()
This solution works very well, most of time. Sometimes it shows a very
strange behavior and comes up with old search results. And it looks
absolutely wrong for me that the AsyncDataProvider is always new created
for every search.
Until now I have no other idea, how I could do this, because in the end,
I need to call my service, which is defined in the AsyncDataProvider.
Is this the right design?
Thanks a lot in advance.
Best regards
Jochen
--
You received this message because you are subscribed to the Google Groups
"Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/groups/opt_out.