我遇到了下一个问题:
我想在 gxt 网格中创建 CRUD 操作,但我遇到了这样的情况:我在表单上将sex
字段设置为 aRadioGroup
并编写了一个用于create
操作的转换器(下面的代码),所以它可以正常工作(下面的实体和转换器代码):
private Long id;
private String name;
private String sex;
formBinding.getBinding(radioGroup).setConverter(new Converter() {
@Override
public Object convertFieldValue(Object value) {
return ((Radio) value).getData("value");
}
});
这是将 radiogroup 添加到我的表单的代码:
Radio radio = new Radio();
radio.setBoxLabel("M");
radio.setData("value", "M");
Radio radio2 = new Radio();
radio2.setBoxLabel("F");
radio.setData("value", "F");
radioGroup = new RadioGroup();
radioGroup.setSelectionRequired(true);
radioGroup.setFieldLabel("Sex");
radioGroup.add(radio);
radioGroup.add(radio2);
radioGroup.setName("sex");
simplePanel.add(radioGroup, formData);
我需要将值从 String 转换为 radio 并将其设置为radiogroup
. 但是当我尝试编写相反的操作,即编辑时,它抛出了这样一个异常:
11:52:23.381 [ERROR] [hellogxt] Uncaught exception escaped
java.lang.ClassCastException: java.lang.String cannot be cast to com.extjs.gxt.ui.client.widget.form.Radio
at com.extjs.gxt.ui.client.widget.form.RadioGroup.setValue(RadioGroup.java:1)
at com.extjs.gxt.ui.client.binding.FieldBinding.updateField(FieldBinding.java:207)
at com.extjs.gxt.ui.client.binding.FieldBinding.bind(FieldBinding.java:82)
at com.extjs.gxt.ui.client.binding.Bindings$1.execute(Bindings.java:92)
at com.google.gwt.user.client.CommandExecutor.doExecuteCommands(CommandExecutor.java:310)
at com.google.gwt.user.client.CommandExecutor$2.run(CommandExecutor.java:205)
at com.google.gwt.user.client.Timer.fire(Timer.java:149)
at sun.reflect.GeneratedMethodAccessor35.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
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.GeneratedMethodAccessor28.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
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(Thread.java:722)
我试图向我的转换器添加一些功能,但似乎活页夹没有调用我的代码(formbinder 在编辑操作中根本没有进入该方法)。