GXT:如何在TreeGrid中添加复选框?

时间:2015-02-05 16:32:03

标签: gwt gxt

我正在使用GXT3.1.2 / GWT2.6 我想在TreeGrid中添加复选框,但效果不佳。 单击复选框时,行中的所有值都将更改为“true”。 当我再次点击时,它会抛出一个异常。请帮忙。

这是我的代码:

    ColumnConfig<OBTInputTuple, Boolean> cc3 = new ColumnConfig<OBTInputTuple, Boolean>(new ValueProvider<OBTInputTuple, Boolean>(){
        @Override
        public Boolean getValue(OBTInputTuple object) {
            return object.isMandatory();
        }

        @Override
        public void setValue(OBTInputTuple object, Boolean value) {
            object.setMandatory(value); 
        }

        @Override
        public String getPath() {
          return null;
        }
    });
    cc3.setCell(new CheckBoxCell());
    cc3.setWidth(200);
    cc3.setHeader("Mandatory");

当我点击一次复选框时: enter image description here

当我再次点击复选框时:

com.google.gwt.event.shared.UmbrellaException: Exception caught: Item was not already in the store, cannot be updated
    at com.google.gwt.event.shared.HandlerManager.fireEvent(HandlerManager.java:129)
    at com.sencha.gxt.data.shared.Store.fireEvent(Store.java:610)
    at com.sencha.gxt.data.shared.Store$Record.addChange(Store.java:174)
    at com.sencha.gxt.widget.core.client.grid.Grid$2.update(Grid.java:878)
    at com.sencha.gxt.cell.core.client.form.CheckBoxCell.onBrowserEvent(CheckBoxCell.java:171)
    at com.sencha.gxt.cell.core.client.form.CheckBoxCell.onBrowserEvent(CheckBoxCell.java:1)
    at com.sencha.gxt.widget.core.client.grid.Grid.fireEventToCell(Grid.java:875)
    at com.sencha.gxt.widget.core.client.grid.Grid.handleEventForCell(Grid.java:907)
    at com.sencha.gxt.widget.core.client.grid.Grid.onBrowserEvent(Grid.java:594)
    at com.google.gwt.user.client.DOM.dispatchEventImpl(DOM.java:1467)
    at com.google.gwt.user.client.DOM.dispatchEvent(DOM.java:1406)
    at com.google.gwt.user.client.impl.DOMImplStandard.dispatchEvent(DOMImplStandard.java:323)
    at sun.reflect.GeneratedMethodAccessor144.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:338)
    at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:219)
    at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:136)
    at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:576)
    at com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:284)
    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:347)
    at sun.reflect.GeneratedMethodAccessor140.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:293)
    at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:547)
    at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:364)
    at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.AssertionError: Item was not already in the store, cannot be updated
    at com.sencha.gxt.data.shared.ListStore.update(ListStore.java:370)
    at com.sencha.gxt.widget.core.client.treegrid.TreeGrid.onRecordChange(TreeGrid.java:1030)
    at com.sencha.gxt.widget.core.client.treegrid.TreeGrid$1.onRecordChange(TreeGrid.java:253)
    at com.sencha.gxt.data.shared.event.StoreRecordChangeEvent.dispatch(StoreRecordChangeEvent.java:113)
    at com.sencha.gxt.data.shared.event.StoreRecordChangeEvent.dispatch(StoreRecordChangeEvent.java:1)
    at com.google.gwt.event.shared.GwtEvent.dispatch(GwtEvent.java:1)
    at com.google.web.bindery.event.shared.EventBus.dispatchEvent(EventBus.java:40)
    at com.google.web.bindery.event.shared.SimpleEventBus.doFire(SimpleEventBus.java:193)
    at com.google.web.bindery.event.shared.SimpleEventBus.fireEvent(SimpleEventBus.java:88)
    at com.google.gwt.event.shared.HandlerManager.fireEvent(HandlerManager.java:127)
    at com.sencha.gxt.data.shared.Store.fireEvent(Store.java:610)
    at com.sencha.gxt.data.shared.Store$Record.addChange(Store.java:174)
    at com.sencha.gxt.widget.core.client.grid.Grid$2.update(Grid.java:878)
    at com.sencha.gxt.cell.core.client.form.CheckBoxCell.onBrowserEvent(CheckBoxCell.java:171)
    at com.sencha.gxt.cell.core.client.form.CheckBoxCell.onBrowserEvent(CheckBoxCell.java:1)
    at com.sencha.gxt.widget.core.client.grid.Grid.fireEventToCell(Grid.java:875)
    at com.sencha.gxt.widget.core.client.grid.Grid.handleEventForCell(Grid.java:907)
    at com.sencha.gxt.widget.core.client.grid.Grid.onBrowserEvent(Grid.java:594)
    at com.google.gwt.user.client.DOM.dispatchEventImpl(DOM.java:1467)
    at com.google.gwt.user.client.DOM.dispatchEvent(DOM.java:1406)
    at com.google.gwt.user.client.impl.DOMImplStandard.dispatchEvent(DOMImplStandard.java:323)
    at sun.reflect.GeneratedMethodAccessor144.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:338)
    at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:219)
    at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:136)
    at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:576)
    at com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:284)
    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:347)
    at sun.reflect.GeneratedMethodAccessor140.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:293)
    at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:547)
    at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:364)
    at java.lang.Thread.run(Unknown Source)

1 个答案:

答案 0 :(得分:2)

最后我明白了! 这是因为     @覆盖     public String getPath(){         return null;     }

我应该让它返回一个字符串值而不是null。 一旦我这样做了。一切都很完美。