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

GXT: How do I add checkbox into TreeGrid?

我使用的是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");

当我点击复选框一次时:

当我再次点击复选框时:

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.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.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.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)

我终于明白了! 是因为
@覆盖 public 字符串 getPath() { return空; }

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