Announcement

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

    How to send an array of integers with JSON/RestDataSource

    Hi,

    Is it possible to send an array with integers with RestDataSource ?

    Currently I've done this:

    public class XDataSource extends RestDataSource {
    public XDataSource()
    {
    setDataFormat(DSDataFormat.JSON);
    setJsonRecordXPath("/");

    DataSourceIntegerField idsField = new DataSourceIntegerField("ids");
    tripIdsField.setMultiple(true);

    setFields(idsField);

    // ... The rest of standard setup of the DataSource ..
    }
    }

    When the server responds with the ID's I get the following error in SC Developer Console:

    04:05:22,202 [ERROR] 13:12:43.956:XRP6:WARN:RestDataSource:XReportDS:XReportDS.ids: value: Array[20] failed on validator: {type: "isInteger", typeCastValidator: true, _generated: true, defaultErrorMessage: "Must be a whole number."}
    com.smartgwt.client.core.JsObject$SGWT_WARN: 13:12:43.956:XRP6:WARN:RestDataSource:XReportDS:XReportDS.ids: value: Array[20] failed on validator: {type: "isInteger",
    typeCastValidator: true,
    _generated: true,
    defaultErrorMessage: "Must be a whole number."} at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27) at java.lang.reflect.Constructor.newInstance(Constructor.java:513) at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:105) 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.BrowserChannel.reactToMessages(BrowserChannel.java:1668) at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:401) at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:222) at java.lang.Thread.run(Thread.java:619)

    So the array is not of type integer. That's correct, but the setMultiple method of DataSourceIntegerField should take care of that ?

    #2
    Has this been resolved/answered? I'm running into an identical issue. An array of integer values in a JSON RestDataSource logs an ERROR, even though the DataSourceIntegerField is setMultiple(true).

    Comment


      #3
      Can you post the complete DataSource definition plus a sample JSON fetch response you're attempting to work with?

      Thanks

      Comment


        #4
        Well, I've determined that the fundamental handling of the integer array seems to work OK, in the sense that the multiple values encoded do show up in my multi-select. I just get a nasty validation-failed error message logged in the developer console. I wasted a bunch of my time trying to eliminate it:

        [ERROR] [prototype_gwt] 16:41:31.067:XRP3:WARN:RestDataSource:isc_RestDataSource_1:isc_RestDataSource_1.assocId: value: Array[2] failed on validator: {type: "isInteger", typeCastValidator: true, _generated: true, defaultErrorMessage: "Must be a whole number."}

        My hope is that this is just a logging issue, but my fear is that there will be some other subtle malfunction as a result that I just haven't noticed yet.

        Here's the code for my test form:
        Code:
        	private Canvas createDSTestPanel() {
        		DynamicForm form = new DynamicForm();
        		form.setDataSource(formDataSource());	
        		form.setAutoFetchData(true);
        		
        		FormItem idItem = new HiddenItem("id");
        		FormItem nameItem  = new TextItem("name");
        		
        		SelectItem assocIdItem = new SelectItem("assocId","Associated Options");
        		assocIdItem.setMultiple(true);
        		assocIdItem.setOptionDataSource(optionDataSource());
        		assocIdItem.setValueField("id");
        		assocIdItem.setDisplayField("name");
        		
        		form.setItems(idItem, nameItem, assocIdItem);
        		
        		return form;
        	}
        
        	private RestDataSource formDataSource() {
        		RestDataSource src = new RestDataSource();
        		src.setDataURL("json/test.json");
        		src.setDataFormat(DSDataFormat.JSON);
        		src.setDataProtocol(DSProtocol.POSTPARAMS);
        		src.addField(new DataSourceIntegerField("id"));
        		src.addField(new DataSourceTextField("name"));
        		DataSourceField assocIdField = new DataSourceIntegerField("assocId");
        		assocIdField.setMultiple(true);
        		src.addField(assocIdField);
        		return src;
        	}
        
        	private RestDataSource optionDataSource() {
        		RestDataSource optSrc = new RestDataSource();
        		optSrc.setDataURL("json/options.json");
        		optSrc.setDataFormat(DSDataFormat.JSON);
        		optSrc.setDataProtocol(DSProtocol.POSTPARAMS);
        		optSrc.addField(new DataSourceIntegerField("id"));
        		optSrc.addField(new DataSourceTextField("name"));
        		return optSrc;
        	}
        Here is test.json, with the array of integers on 'assocId':
        Code:
        { "response" : { "status" : 0, "startRow" : 0, "endRow" : 0, "totalRows" : 1,
        	"data" : [{
        			"id" : 8456,
        			"name" : "My Contents",
        			"assocId" : [ 1, 3 ]
        		}]
        	}
        }
        And options.json:
        Code:
        { "response" : { "status" : 0, "startRow" : 0, "endRow" : 3, "totalRows" : 4,
        	"data" : [ { "id" : 1, "name" : "Option 1" },
        		{ "id" : 2, "name" : "Option 2" },
        		{ "id" : 3, "name" : "Option 3" },
        		{ "id" : 4, "name" : "Option 4" }
        		]
        	}
        }

        Comment


          #5
          Same problem here.
          Workaround: try to use general DataSourceField instead of DataSourceIntegerField to eliminate the built-in validation warning.

          Comment

          Working...
          X