Hi,
I have a custom datasource and am trying to add a DataSourceField and then set the corresponding attribute with Record.setAttributeAsJavaObject. In my DynamicForm I have created and added a custom FormItem that extends CanvasItem and calls CanvasItem.addShowValueHandler.
My problem is that when I call DynamicForm.editRecord(Record) something goes wrong and I dont get the java object in the CanvasItem.addShowValueHandler. Instead I get a JavaScriptObject.
Code snippets: In my CustomDataSource:
And
In my custom form items ShowValueHandler.onShowValue:
The output of above when running in gwt devmode:
But, when I deploy my webapp I get the Converting to java array and the conversion works fine (but I am really expecting a String[] here).
After some debugging I found references to an attribute called deepCloneOnEdit, and if I add:
Then it works fine, and I get the we actually got an String[]! above. Both when deploying and running in gwt devmode.
I suspect that somewhere in the code smartgwt tries to copy the java String[] object, but fails (in devmode).
If the record.setAttributeAsJavaObject is called with a custom POJO (array) it also ends up in a JavaScriptObject (array) which makes it impossible to get my original POJO (array) unless I set the deepCloneOnEdit to true.
Have I missed something or is deepCloneOnEdit=true the right way to solve it?
Above is when using smartgwt-4.0p from 2014-03-18 (LGPL) (SmartClient Version: v9.0p_2014-03-18/LGPL Development Only (built 2014-03-18)), GWT 2.6.0, Chrome Version 32.0.1700.102, Linux Ubuntu 12.04.But I am seeing the same thing with SmartClient Version: SNAPSHOT_v10.0d_2014-03-18/LGPL Development Only (built 2014-03-18) and SmartClient Version: v9.1p_2014-03-18/LGPL Development Only (built 2014-03-18)
Regards
/Johannes
I have a custom datasource and am trying to add a DataSourceField and then set the corresponding attribute with Record.setAttributeAsJavaObject. In my DynamicForm I have created and added a custom FormItem that extends CanvasItem and calls CanvasItem.addShowValueHandler.
My problem is that when I call DynamicForm.editRecord(Record) something goes wrong and I dont get the java object in the CanvasItem.addShowValueHandler. Instead I get a JavaScriptObject.
Code snippets: In my CustomDataSource:
Code:
DataSourceField testField = new DataSourceField(test, FieldType.ANY);
Code:
record.setAttributeAsJavaObject(test, new String[] { "string1", "string2" });
Code:
public void onShowValue(ShowValueEvent event) {
Object value = event.getDataValue();
Utils.logInfo("value=" + value);
Utils.logInfo("value.getClass=" + value.getClass());
if (value instanceof String[]) {
Utils.logInfo("we actually got an String[]!");
return;
}
Record valueRecord = event.getDataValueAsRecord();
String[] attributes = valueRecord.getAttributes();
for (String string : attributes) {
Utils.logInfo("attrib:" + string);
Object attribute = valueRecord.getAttributeAsObject(string);
Utils.logInfo("attribute=" + attribute);
Utils.logInfo("attribute.getClass=" + attribute.getClass());
if (attribute instanceof RuntimeException) {
RuntimeException e = (RuntimeException) attribute;
printStackTrace(e);
}
}
if (value instanceof JavaScriptObject) {
JavaScriptObject jsObj = (JavaScriptObject) value;
Utils.logInfo("Converting to java array");
String[] convertToJavaStringArray = JSOHelper.convertToJavaStringArray(jsObj);
for (String string : convertToJavaStringArray) {
Utils.logInfo("item=" + string);
}
}
}
Code:
value=[object Object]
value.getClass=class com.google.gwt.core.client.JavaScriptObject$
attrib:0
attribute=java.lang.RuntimeException
attribute.getClass=class java.lang.RuntimeException
e=null
com.google.gwt.dev.shell.JavaDispatchImpl JavaDispatchImpl.java:123
com.google.gwt.dev.shell.JsValueOOPHM$DispatchObjectOOPHM JsValueOOPHM.java:55
com.google.gwt.dev.shell.OophmSessionHandler OophmSessionHandler.java:83
com.google.gwt.dev.shell.BrowserChannelServer BrowserChannelServer.java:687
com.google.gwt.dev.shell.BrowserChannelServer BrowserChannelServer.java:344
com.google.gwt.dev.shell.BrowserChannelServer BrowserChannelServer.java:219
com.google.gwt.dev.shell.ModuleSpaceOOPHM ModuleSpaceOOPHM.java:136
com.google.gwt.dev.shell.ModuleSpace ModuleSpace.java:576
com.google.gwt.dev.shell.ModuleSpace ModuleSpace.java:304
com.google.gwt.dev.shell.JavaScriptHost JavaScriptHost.java:107
com.smartgwt.client.widgets.form.DynamicForm DynamicForm.java:-1
com.test.TestPanel$8 TestPanel.java:796
sun.reflect.NativeMethodAccessorImpl NativeMethodAccessorImpl.java:-2
sun.reflect.NativeMethodAccessorImpl NativeMethodAccessorImpl.java:57
sun.reflect.DelegatingMethodAccessorImpl DelegatingMethodAccessorImpl.java:43
java.lang.reflect.Method Method.java:606
com.google.gwt.dev.shell.MethodAdaptor MethodAdaptor.java:103
com.google.gwt.dev.shell.MethodDispatch MethodDispatch.java:71
com.google.gwt.dev.shell.OophmSessionHandler OophmSessionHandler.java:172
com.google.gwt.dev.shell.BrowserChannelServer BrowserChannelServer.java:338
com.google.gwt.dev.shell.BrowserChannelServer BrowserChannelServer.java:219
com.google.gwt.dev.shell.ModuleSpaceOOPHM ModuleSpaceOOPHM.java:136
com.google.gwt.dev.shell.ModuleSpace ModuleSpace.java:576
com.google.gwt.dev.shell.ModuleSpace ModuleSpace.java:284
com.google.gwt.dev.shell.JavaScriptHost JavaScriptHost.java:91
com.google.gwt.core.client.impl.Impl Impl.java:-1
com.google.gwt.core.client.impl.Impl Impl.java:347
sun.reflect.GeneratedMethodAccessor560 null:-1
sun.reflect.DelegatingMethodAccessorImpl DelegatingMethodAccessorImpl.java:43
java.lang.reflect.Method Method.java:606
com.google.gwt.dev.shell.MethodAdaptor MethodAdaptor.java:103
com.google.gwt.dev.shell.MethodDispatch MethodDispatch.java:71
com.google.gwt.dev.shell.OophmSessionHandler OophmSessionHandler.java:172
com.google.gwt.dev.shell.BrowserChannelServer BrowserChannelServer.java:338
com.google.gwt.dev.shell.BrowserChannelServer BrowserChannelServer.java:219
com.google.gwt.dev.shell.ModuleSpaceOOPHM ModuleSpaceOOPHM.java:136
com.google.gwt.dev.shell.ModuleSpace ModuleSpace.java:576
com.google.gwt.dev.shell.ModuleSpace ModuleSpace.java:304
com.google.gwt.dev.shell.JavaScriptHost JavaScriptHost.java:107
com.smartgwt.client.data.DataSource DataSource.java:-1
com.test.CustomDataSource$PagedCallBack CustomDataSource.java:513
com.test.CustomDataSource$PagedCallBack CustomDataSource.java:1
com.google.gwt.user.client.rpc.impl.RequestCallbackAdapter RequestCallbackAdapter.java:232
com.google.gwt.http.client.Request Request.java:259
com.google.gwt.http.client.RequestBuilder$1 RequestBuilder.java:412
sun.reflect.NativeMethodAccessorImpl NativeMethodAccessorImpl.java:-2
sun.reflect.NativeMethodAccessorImpl NativeMethodAccessorImpl.java:57
sun.reflect.DelegatingMethodAccessorImpl DelegatingMethodAccessorImpl.java:43
java.lang.reflect.Method Method.java:606
com.google.gwt.dev.shell.MethodAdaptor MethodAdaptor.java:103
com.google.gwt.dev.shell.MethodDispatch MethodDispatch.java:71
com.google.gwt.dev.shell.OophmSessionHandler OophmSessionHandler.java:172
com.google.gwt.dev.shell.BrowserChannelServer BrowserChannelServer.java:338
com.google.gwt.dev.shell.BrowserChannelServer BrowserChannelServer.java:219
com.google.gwt.dev.shell.ModuleSpaceOOPHM ModuleSpaceOOPHM.java:136
com.google.gwt.dev.shell.ModuleSpace ModuleSpace.java:576
com.google.gwt.dev.shell.ModuleSpace ModuleSpace.java:284
com.google.gwt.dev.shell.JavaScriptHost JavaScriptHost.java:91
com.google.gwt.core.client.impl.Impl Impl.java:-1
com.google.gwt.core.client.impl.Impl Impl.java:347
sun.reflect.GeneratedMethodAccessor560 null:-1
sun.reflect.DelegatingMethodAccessorImpl DelegatingMethodAccessorImpl.java:43
java.lang.reflect.Method Method.java:606
com.google.gwt.dev.shell.MethodAdaptor MethodAdaptor.java:103
com.google.gwt.dev.shell.MethodDispatch MethodDispatch.java:71
com.google.gwt.dev.shell.OophmSessionHandler OophmSessionHandler.java:172
com.google.gwt.dev.shell.BrowserChannelServer BrowserChannelServer.java:293
com.google.gwt.dev.shell.BrowserChannelServer BrowserChannelServer.java:547
com.google.gwt.dev.shell.BrowserChannelServer BrowserChannelServer.java:364
java.lang.Thread Thread.java:724
After some debugging I found references to an attribute called deepCloneOnEdit, and if I add:
Code:
DataSourceField testField = new DataSourceField(test, FieldType.ANY);
testField.setAttribute(deepCloneOnEdit, false);
I suspect that somewhere in the code smartgwt tries to copy the java String[] object, but fails (in devmode).
If the record.setAttributeAsJavaObject is called with a custom POJO (array) it also ends up in a JavaScriptObject (array) which makes it impossible to get my original POJO (array) unless I set the deepCloneOnEdit to true.
Have I missed something or is deepCloneOnEdit=true the right way to solve it?
Above is when using smartgwt-4.0p from 2014-03-18 (LGPL) (SmartClient Version: v9.0p_2014-03-18/LGPL Development Only (built 2014-03-18)), GWT 2.6.0, Chrome Version 32.0.1700.102, Linux Ubuntu 12.04.But I am seeing the same thing with SmartClient Version: SNAPSHOT_v10.0d_2014-03-18/LGPL Development Only (built 2014-03-18) and SmartClient Version: v9.1p_2014-03-18/LGPL Development Only (built 2014-03-18)
Regards
/Johannes