0

I'm using popup panel of gwt platform and the popup contains two panels on the top panel i have some textboxes and a search button.

and in the second panel contails a cell table which automatically loads some data from db as soon as popup pops out. and from the top panel also i should be able to search for specific data and update the cell table. i'm using the following code to update the CellTable

public void update(List<UserData> data){
        dataProvider.getList().clear();
        List<UserData> dataList=dataProvider.getList();
        for (UserData rtaData : data) {
            dataList.add(rtaData);
        }
        dataProvider.addDataDisplay(cellTable);     
    }

my code is working fine but when i see the gwt development mode window in eclipse i can see the following error when ever i click on search button.

14:46:25.796 [ERROR] [gwtemotor] Uncaught exception escaped

    java.lang.IllegalStateException: The specified display has already been added to this adapter.
        at com.google.gwt.view.client.AbstractDataProvider.addDataDisplay(AbstractDataProvider.java:83)
        at com.bagi.emotor.client.ui.presenter.RTOLocationView.update(RTOLocationView.java:230)
        at com.bagi.emotor.client.ui.presenter.RTOLocationPresenter$2.onSuccess(RTOLocationPresenter.java:85)
        at com.bagi.emotor.client.ui.presenter.RTOLocationPresenter$2.onSuccess(RTOLocationPresenter.java:1)
        at com.gwtplatform.dispatch.client.DefaultDispatchAsync.onExecuteSuccess(DefaultDispatchAsync.java:229)
        at com.gwtplatform.dispatch.client.DefaultDispatchAsync$2.onSuccess(DefaultDispatchAsync.java:137)
        at com.gwtplatform.dispatch.client.DefaultDispatchAsync$2.onSuccess(DefaultDispatchAsync.java:1)
        at com.google.gwt.user.client.rpc.impl.RequestCallbackAdapter.onResponseReceived(RequestCallbackAdapter.java:232)
        at com.google.gwt.http.client.Request.fireOnResponseReceived(Request.java:287)
        at com.google.gwt.http.client.RequestBuilder$1.onReadyStateChange(RequestBuilder.java:395)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
        at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
        at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172)
        at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessagesWhileWaitingForReturn(BrowserChannelServer.java:337)
        at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:218)
        at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:136)
        at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:561)
        at com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:269)
        at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeObject(JavaScriptHost.java:91)
        at com.google.gwt.core.client.impl.Impl.apply(Impl.java)
        at com.google.gwt.core.client.impl.Impl.entry0(Impl.java:213)
        at sun.reflect.GeneratedMethodAccessor34.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
        at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
        at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172)
        at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessages(BrowserChannelServer.java:292)
        at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:546)
        at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:363)
        at java.lang.Thread.run(Unknown Source)

even though i'm app is working i need to understand why this error is coming,

Thanks,

4

2 回答 2

0

You are invoking dataProvider.addDataDisplay(cellTable); on every invocation of the update(List<UserData> data) . addDataDisplay needs to be invoked only once per view.

If You have multiple views, the mvp way is

View 1 -> cellTable
View 2 -> cellTree
Presenter -> dataProvider

dataProvider.addDataDisplay(cellTable) 
dataProvider.addDataDisplay(cellTree) 

Solution

Move dataProvider.addDataDisplay into your constructor or lazy initialize it in update(List<UserData> data);

boolean initialized = false;

public void update(List<UserData> data){
        dataProvider.getList().clear();
        if(!initialized) {
          dataProvider.addDataDisplay(cellTable);
          initialized = true;
        } 
        List<UserData> dataList=dataProvider.getList();
        for (UserData rtaData : data) {
            dataList.add(rtaData);
        }

    }
于 2013-01-07T09:48:46.763 回答
0

The statement dataProvider.addDataDisplay(cellTable) adds a data display to this adapter. The current range of interest of the display will be populated with data.

If data display is already added and you try to add this again, it will throw this error.

To avoid this error, you can check condition and remove added display before add same data display. i.e:

if (getProvider().getDataDisplays().contains(cellTable)) {
            getProvider().removeDataDisplay(cellTable);
   }
getProvider().addDataDisplay(cellTable);
于 2013-01-07T09:48:54.087 回答