Is there a simple way to create a Record (client side) from the Map returned by ValuesManager.getValues()?
Announcement
Collapse
No announcement yet.
X
-
Here is the code I'm currently using to construct a new record from a subset of the values in a ValuesManager. I need to get just the fields that are in a particular datasource (poItemDetailDS in this case) and construct a Record from them. This seems to work.
Code:ArrayList<Record> detailRecs = new ArrayList<Record>(); Record detailRec = new Record(); Map<String, Object> details = new HashMap<String, Object>(getPoItemValuesManager().getValues()); details.keySet().retainAll(Arrays.asList(poItemDetailDS.getFieldNames())); for (String key : details.keySet()) { detailRec.setAttribute(key, details.get(key)); } detailRecs.add(detailRec);
Code:Record[] detailRecsArray = new Record[detailRecs.size()]; getPoItemValuesManager().setValue("PoItemDetails", detailRecs.toArray(detailRecsArray));
Code:Caused by: com.google.gwt.core.client.JavaScriptException: (null): null at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:237) at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:126) at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:561) at com.google.gwt.dev.shell.ModuleSpace.invokeNativeVoid(ModuleSpace.java:289) at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeVoid(JavaScriptHost.java:107) at com.smartgwt.client.widgets.form.ValuesManager.saveData(ValuesManager.java) at com.islandpacific.gui.client.PoItemEditor.savePoItem(PoItemEditor.java:627) at com.islandpacific.gui.client.PoItemEditor.access$11(PoItemEditor.java:569) at com.islandpacific.gui.client.PoItemEditor$30.onClick(PoItemEditor.java:1664) at com.smartgwt.client.widgets.events.ClickEvent.dispatch(ClickEvent.java:98) at com.smartgwt.client.widgets.events.ClickEvent.dispatch(ClickEvent.java:1) at com.google.gwt.event.shared.SimpleEventBus.doFire(SimpleEventBus.java:204) at com.google.gwt.event.shared.SimpleEventBus.fireEvent(SimpleEventBus.java:103) at com.google.gwt.event.shared.HandlerManager.fireEvent(HandlerManager.java:96) at com.smartgwt.client.widgets.BaseWidget.fireEvent(BaseWidget.java:66) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) 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:157) at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessagesWhileWaitingForReturn(BrowserChannelServer.java:326) at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:207) at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:126) 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:214) at sun.reflect.GeneratedMethodAccessor193.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) 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:157) at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessages(BrowserChannelServer.java:281) at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:531) at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:352) at java.lang.Thread.run(Thread.java:680)
Code:Evaluator: result of 'isc_ValuesManager_3.values.PoItemDetails...' (0ms): [Obj ]
-
I changed my code as follows to avoid the problem. In this particular case I know there are only integer and text fields involved so I don't have to check for other types. But why can't I just get the values from the ValuesManager using VM.getValues().get("FieldName") and not worry about what type they are? And a related question ... why is there only ValuesManager.getValueAsString and not ValuesManager.getValueAsInt, etc.
Code:Record detailRec = new Record(); for (DataSourceField field : poItemDetailDS.getFields()) { if (getPoItemValuesManager().getValueAsString(field.getName()) != null) { if (field.getType()==FieldType.INTEGER) detailRec.setAttribute(field.getName(), Integer.parseInt(getPoItemValuesManager().getValueAsString(field.getName()))); else detailRec.setAttribute(field.getName(), getPoItemValuesManager().getValueAsString(field.getName())); } } detailRecs.add(detailRec);
Comment
-
Just tried it and I do not get the same javascript error running the compiled version. It does submit the request, but the PoItemDetails attribute looks like this, which generates errors on the server when trying to use it. All of the integer fields become structures with the integer value shows as "value_0" followed by a "castableTypeMap$" array. ??
Code:"PoItemDetails":[ { "IGTIN":"05050923536044", "ICLR":{ "value_0":2, "castableTypeMap$":{ "27":1, "29":1, "198":1, "201":1 } }, "IPWM#1":{ "value_0":0, "castableTypeMap$":{ "27":1, "29":1, "198":1, "201":1 } }, "IOVC":"BLACK", "ISBN":"", "IGTINTP":"2", "ISKU":{ "value_0":1958, "castableTypeMap$":{ "27":1, "29":1, "198":1, "201":1 } }, "ISIZ":{ "value_0":1, "castableTypeMap$":{ "27":1, "29":1, "198":1, "201":1 } }, "IQTY":{ "value_0":99, "castableTypeMap$":{ "27":1, "29":1, "198":1, "201":1 } } } ]
Comment
Comment