Announcement

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

    High Precision doubles converted to Strings using custom operation DMI data source

    Description I invoke a simple DMI request which returns double values of varying precision. I view the types of the results on the client side.

    Actual results Those with 14 or 15 decimal places are Strings when viewed on the client side. The rest are doubles.

    Expected results All values should show up on the client side as doubles, not Strings.

    NOTE I ran this in GWT development mode

    Screen shot of actual results:

    Click image for larger version

Name:	2-11-2016 9-40-26 AM.png
Views:	60
Size:	25.7 KB
ID:	234820

    SmartClient Version: v10.1p_2016-01-14/Enterprise Deployment (built 2016-01-14)

    Chrome browser, Version 48.0.2564.109 m

    The DSRequest from the log console
    Code:
    {
        dataSource:"example", 
        operationType:"custom", 
        operationId:"example", 
        data:{
        }, 
        textMatchStyle:"exact", 
        showPrompt:true, 
        oldValues:{
        }, 
        requestId:"example_request1", 
        fallbackToEval:false, 
        lastClientEventThreadCode:"XRP4", 
        bypassCache:true, 
        dataProtocol:"getParams"
    }
    The DSResponse from the log console
    Code:
    {
        affectedRows:0, 
        data:[
            {
                value08:127.1500000018, 
                value07:127.15000000018, 
                value09:127.150000018, 
                value04:"127.15000000000018", 
                value03:"127.15000000000002", 
                value06:127.150000000018, 
                value05:127.1500000000018, 
                value10:127.15000018, 
                value02:127.15, 
                value01:127.15
            }
        ], 
        invalidateCache:false, 
        isDSResponse:true, 
        operationType:"custom", 
        queueStatus:0, 
        status:0
    }
    The server side method invoked
    Code:
    public DSResponse example(DSRequest dsRequest, HttpServletRequest request)
        {
            Map<String, Object> map = new HashMap<>();
            map.put("value01", 127.15000000000000018);
            map.put("value02", 127.1500000000000018);
            map.put("value03", 127.150000000000018);
            map.put("value04", 127.15000000000018);
            map.put("value05", 127.1500000000018);
            map.put("value06", 127.150000000018);
            map.put("value07", 127.15000000018);
            map.put("value08", 127.1500000018);
            map.put("value09", 127.150000018);
            map.put("value10", 127.15000018);
    
            List<Map<String, Object>> data = new ArrayList<>();
            data.add(map);
    
            return new DSResponse(data);
        }
    Client side code
    Code:
    package example.client.jsonstringnumber;
    
    import java.util.Arrays;
    
    import com.google.gwt.core.client.EntryPoint;
    import com.smartgwt.client.core.Function;
    import com.smartgwt.client.data.DSCallback;
    import com.smartgwt.client.data.DSRequest;
    import com.smartgwt.client.data.DSResponse;
    import com.smartgwt.client.data.DataSource;
    import com.smartgwt.client.data.Record;
    import com.smartgwt.client.widgets.HTMLFlow;
    
    public class JsonStringNumber implements EntryPoint
    {
    
        @Override
        public void onModuleLoad()
        {
            final String id = "example";
            DataSource.load(id, new Function()
            {
                @Override
                public void execute()
                {
                    runExampleWithDS(DataSource.get(id));
                }
            });
        }
    
        private void runExampleWithDS(DataSource ds)
        {
            String operationId = "example";
            Record data = new Record();
            ds.performCustomOperation(operationId, data, new DSCallback()
            {
                @Override
                public void execute(DSResponse dsResponse, Object data, DSRequest dsRequest)
                {
                    Record record = dsResponse.getData()[0];
    
                    String msg = extractValuesFromRecordAsMessage(record);
    
                    HTMLFlow htmlFlow = new HTMLFlow();
                    htmlFlow.setWidth(700);
                    htmlFlow.setContents(msg);
                    htmlFlow.draw();
                }
    
                private String extractValuesFromRecordAsMessage(Record record)
                {
                    String[] keys = record.getAttributes();
                    Arrays.sort(keys);
    
                    String msg1 = "";
                    for (String key : keys)
                    {
                        Object value = record.getAttributeAsObject(key);
                        msg1 += msgForKeyValuePair(key, value);
                    }
                    return msg1;
                }
    
                private String msgForKeyValuePair(String key, Object value)
                {
                    String msg = "<br/><br/>map.get(" + key + ") is " + value;
                    if (value != null)
                    {
                        msg += " and has type " + value.getClass();
                    }
                    return msg;
                }
            });
        }
    
    }
    Data source xml file
    Code:
    <DataSource ID="example">
        <operationBindings>
            <binding operationType="custom" operationId="example" serverMethod="example">
                <serverObject className="example.server.Example"
                    lookStyle="new" />
            </binding>    
        </operationBindings>
    </DataSource>


    #2
    See dataSourceField.stringInBrowser.

    Comment


      #3
      as per the suggestions in the documentation, I put datasource.defaultStringInBrowser=false in server.properties. This has resolved the issue.

      Comment

      Working...
      X