onRangeChanged multiple call issue

74 views
Skip to first unread message

Grisha Shoihet

unread,
Oct 19, 2014, 1:11:05 PM10/19/14
to google-we...@googlegroups.com
hello,

I am new in GWT and try to implement AsyncDataProvider with  DataGrid and SimplePager.
All working as expected except strange behavior in SearchResultsAsyncDataProvider.
I need to update DataGrid each time with new results and it is working , but when I try to use pagination seems that DataGrid  fire events for all previous results also(maybe its related to history mechanism).

Please advice if you have any idea?
I use mvp with activities and places parent.

public class SearchResultsAsyncDataProvider extends AsyncDataProvider<SearchDocument> {

Logger logger = Logger.getLogger("SearchResultsAsyncDataProvider");
private final ClientFactory clientFactory;
private String searchQuery = null;

public SearchResultsAsyncDataProvider(String searchQuery,final ClientFactory clientFactory) {
this.searchQuery = searchQuery;
this.clientFactory = clientFactory;
}

/**
* {@link #onRangeChanged(HasData)} is called when the table requests a new
* range of data. You can push data back to the displays using
* {@link #updateRowData(int, List)}.
*/
@Override
protected void onRangeChanged(HasData<SearchDocument> display) {

//here i expect to once access...

}
---------------------------------------------------------------------------------------------------------------------------------------------------------------
public class SearchResultsViewImpl extends Composite implements SearchResultsView{

private static SearchResultsViewImplUiBinder uiBinder = GWT.create(SearchResultsViewImplUiBinder.class);

interface SearchResultsViewImplUiBinder extends UiBinder<Widget, SearchResultsViewImpl> {}

@UiField
Label labelInformation;
@UiField(provided = true)
DataGrid<SearchDocument> dataGridSearchResults;
@UiField(provided = true)
SimplePager simplePagerSearchResults;
private SearchResultsPresenter searchResultsPresenter;
private SearchResultsAsyncDataProvider searchResultsAsyncDataProvider;
private final String COLUMN_NAME = "Name";
private TextColumn<SearchDocument> columnName;

public SearchResultsViewImpl() 
{
this.dataGridSearchResults = new DataGrid<SearchDocument>();
this.dataGridSearchResults.setEmptyTableWidget(new Label("No Data to Display"));
this.simplePagerSearchResults = new SimplePager();
initWidget(uiBinder.createAndBindUi(this));
//this.setSize("500px", "500px");
this.dataGridSearchResults.setSize("500px","500px");
this.buildGrid();
}

private void buildGrid() 
{
// Build each of the 7 columns
columnName = buildColumnName();

// Add the columns to the widget
this.dataGridSearchResults.addColumn(columnName,  
buildHeader(COLUMN_NAME), buildHeader(COLUMN_NAME));

this.dataGridSearchResults.setColumnWidth(0, 60, Unit.PX);
// Make efficient for IE
//this.dataGridSearchResults.setSkipRowHoverCheck(true);
//this.dataGridSearchResults.setSkipRowHoverFloatElementCheck(true);
//this.dataGridSearchResults.setSkipRowHoverStyleUpdate(true);
}
private TextColumn<SearchDocument> buildColumnName()
{
columnName = new TextColumn<SearchDocument>() 
{
@Override
public String getValue(SearchDocument object) 
{
return object.getName();
}
};
columnName.setDataStoreName(COLUMN_NAME);
columnName.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT);
columnName.setVerticalAlignment(HasVerticalAlignment.ALIGN_TOP);
return columnName;
}
private Header<String> buildHeader(final String text){
Header<String> head = new Header<String>(new TextCell()){
@Override
public String getValue() {
return text;
}
};
return head;
}

private void addColumnSortAsyncHandling() {
columnName.setSortable(true);
// columnTitle.setSortable(true);
// columnDate.setSortable(true);

ColumnSortEvent.AsyncHandler columnSortHandler = 
new ColumnSortEvent.AsyncHandler(this.dataGridSearchResults);
this.dataGridSearchResults.addColumnSortHandler(columnSortHandler);
}
private void createAsyncDataProvider() {
this.searchResultsAsyncDataProvider = 
new SearchResultsAsyncDataProvider(
this.searchResultsPresenter.getSearchQuery(),
this.searchResultsPresenter.getClientFactory());
this.dataGridSearchResults.setVisibleRangeAndClearData(new Range(0,15), true);
//this.dataGridSearchResults.setPageSize(15);
this.simplePagerSearchResults.setDisplay(this.dataGridSearchResults);
this.simplePagerSearchResults.startLoading();
this.searchResultsAsyncDataProvider.addDataDisplay(this.dataGridSearchResults);
//call presenter here to get estimation from db for update row count 
this.searchResultsAsyncDataProvider.updateRowCount(55, true);
this.labelInformation.setText("Search results for : \""+this.searchResultsPresenter.getSearchQuery()+"\"");
//addColumnSortAsyncHandling();
}

@Override
public void reset() {
this.createAsyncDataProvider();
}

@Override
public void setSearchResultsPresenter(
SearchResultsPresenter searchResultsPresenter) {
this.searchResultsPresenter = searchResultsPresenter;
}
}
---------------------------------------------------------------------------------------------------------------------------------------------------

public class SearchResultsActivity extends AbstractActivity implements SearchResultsPresenter{

// Used to obtain views, eventBus, placeController
private final ClientFactory clientFactory;
private SearchResultsView searchResultsView = null;
private SearchResultsPlace searchResultsPlace = null;
public SearchResultsActivity(SearchResultsPlace searchResultsPlace, final ClientFactory clientFactory){
this.clientFactory = clientFactory;
this.searchResultsPlace = searchResultsPlace;
}
@Override
public void start(AcceptsOneWidget panel, EventBus eventBus) {
//reset view here . clear adapter set new keyword etc...
this.searchResultsView = this.clientFactory.getSearchResultsView(this);
this.searchResultsView.reset();
panel.setWidget(this.searchResultsView.asWidget());
}
@Override
public void goTo(Place place) {
this.clientFactory.getPlaceController().goTo(place);
}

@Override
public ClientFactory getClientFactory() {
return this.clientFactory;
}

@Override
public String getSearchQuery() {
return this.searchResultsPlace.getValue();
}
}
--------------------------------------------------------------------------------------------------------------------------------



Juan Pablo Gardella

unread,
Oct 20, 2014, 7:58:32 AM10/20/14
to google-we...@googlegroups.com
Probably you registered more than one the handler. 

--
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 google-web-tool...@googlegroups.com.
To post to this group, send email to google-we...@googlegroups.com.
Visit this group at http://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.

Grisha Shoihet

unread,
Oct 20, 2014, 9:27:05 AM10/20/14
to google-we...@googlegroups.com
On datagrid object ?
How possible to check this?
Thanks

Juan Pablo Gardella

unread,
Oct 20, 2014, 9:37:16 AM10/20/14
to google-we...@googlegroups.com
When the activity starts you are calling reset method on the view (singleton?) and creating a new provider. The previous one was not unregistered (removeDisplay method). 

Grisha Shoihate

unread,
Oct 21, 2014, 4:36:26 AM10/21/14
to google-we...@googlegroups.com

You are talking about asyncdataprovider or activity presenter ?
Maybe i can create singleton activity and this will solve the issue?

You received this message because you are subscribed to a topic in the Google Groups "Google Web Toolkit" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-web-toolkit/ZYe7iYsMHds/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-web-tool...@googlegroups.com.

Grisha Shoihate

unread,
Oct 23, 2014, 11:03:07 AM10/23/14
to google-we...@googlegroups.com
thanks a lot
the solution was as you advice removeDataDisplay before create new
searchResultsAsyncDataProvider :
private void createAsyncDataProvider() {
if(this.searchResultsAsyncDataProvider!=null){
searchResultsAsyncDataProvider.removeDataDisplay(this.dataGridSearchResults);
}
this.searchResultsAsyncDataProvider =
new SearchResultsAsyncDataProvider(
this.searchResultsPPPresenter.getSearchQuery(),
this.searchResultsPPPresenter.getClientFactory());
> You received this message because you are subscribed to a topic in the
> Google Groups "Google Web Toolkit" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/google-web-toolkit/ZYe7iYsMHds/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
--
Thanks
Reply all
Reply to author
Forward
0 new messages