PDA

View Full Version : how to map String to Radio in binder



userio
11 Mar 2013, 2:44 AM
Hi all!

I've faced the next issue:


I want to create CRUD-operations in gxt grid, but I've run into a such situation:
I made `sex` field as a `RadioGroup` on the form and wrote a converter for `create` operation(code below), so it works normally(entity and converter code below):



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




Here is code for adding radiogroup to my form:



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


I need to convert the value from String to radio and set it to the `radiogroup`.
but when I tried to write the opposite operation, i.e. editing, it throws me such an exception:



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)




I've tried to add some functionality to my converter, but it seems that binder doesn't invoke my code(formbinder doesn't step into the method at all at edit operation).