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,

SKM
  • 71
  • 1
  • 10

2 Answers2

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);
        }

    }
appbootup
  • 9,537
  • 3
  • 33
  • 65
  • please make `dataProvider.getList().clear();` as first line of the method. – SKM Jan 08 '13 at 06:42
  • Any particular reason you are adding one item at a time instead of dataProvider.setList( data ) . – appbootup Jan 08 '13 at 07:04
  • Noo, i didn't check there is a setList method in LDP, following is final code after youe suggestion `boolean initialized=false; public void update(List data){ dataProvider.getList().clear(); if (!initialized) { dataProvider.addDataDisplay(cellTable); initialized=true; } dataProvider.setList(data); }` – SKM Jan 17 '13 at 10:04
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);
bNd
  • 7,512
  • 7
  • 39
  • 72
  • @SSR yeah it is wrong approach :( here it can also initialize once and used and avoid this error. but I would like to know can you please tell me when such case required where needs to remove data display? because provider has `removeDataDisplay` so it may have some intention!! – bNd Jan 07 '13 at 12:04
  • If you have 2 views attached to same data and one view needs to be removed in a page/screen it makes sense to remove it. – appbootup Jan 08 '13 at 06:59