Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    How to create a Record from the Map returned by ValuesManager.getValues()

    Is there a simple way to create a Record (client side) from the Map returned by ValuesManager.getValues()?

    #2
    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);
    I put the new Record into an ArrayList because in other cases there may be multiple records. In this case there is only one. The ArrayList gets added to the ValuesManager values like this.
    Code:
    Record[] detailRecsArray = new Record[detailRecs.size()];
    getPoItemValuesManager().setValue("PoItemDetails", detailRecs.toArray(detailRecsArray));
    All seems fine until I then call saveData() on the ValuesManager. That results in a (null) null error. I can't see anything in the error that helps me identify the problem.
    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)
    I've examined the ValuesManager just prior to the call to saveData and I see the PoItemDetails attribute is an Array of 1 element. But when I try to examine that element via the dev console it doesn't eval.
    Code:
    Evaluator: result of 'isc_ValuesManager_3.values.PoItemDetails...' (0ms):
    [Obj
    ]
    But evaluating isc_ValuesManager_3.values.PoItemDetails[0] gets no response whatsoever.

    Comment


      #3
      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


        #4
        I'm unable to reproduce the com.google.gwt.core.client.JavaScriptException posted in your earlier post. Can you post a standalone testcase?

        Comment


          #5
          I probably won't have time soon to create a standalone test case but I have verified with the latest nightly build that the exception still occurs if I switch my code back to the first example.

          Comment


            #6
            Do you see any error in web mode?

            Comment


              #7
              Not sure what you mean by web mode. Do you mean running the compiled version?

              Comment


                #8
                yes, the compiled version.

                Comment


                  #9
                  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


                    #10
                    Can you also post the data when you compile and run your app with the workaround?

                    Comment


                      #11
                      Here it is ...
                      Code:
                                  "PoItemDetails":[
                                      {
                                          "ICLR":2, 
                                          "ISIZ":1, 
                                          "IQTY":99, 
                                          "IPWM#1":0, 
                                          "IOVC":"BLACK", 
                                          "IGTIN":"05050923536044", 
                                          "IGTINTP":"2", 
                                          "ISKU":1958, 
                                          "ISBN":""
                                      }
                                  ]

                      Comment


                        #12
                        This has been fixed, please try the next nightly build.

                        Comment

                        Working...
                        X