Search code examples
javajsongwtdatasourcesmartgwt

Using DataSource Without Data URL


I have a legacy situation whereas the software currently transforms the returned response into an internal JSON formatted String. Is it possible for a DataSource to operate on a JSON formatted String for read-only purposes? The DataSource would be used to populate a ListGrid. How can I set the data URL to a String in memory? Would it be better to add the data manually to the DataSource using addData()?


Solution

  • I determined that I was able to use the SmartGWT utility class JSON to decode my JSON into a custom JavaScriptObject.

    import com.google.gwt.core.client.JavaScriptObject;
    
    public class MyStatusResults extends JavaScriptObject
    {
    
       protected MyStatusResults()
       {
          // Intentionally empty
       }
    
       /**
        * Returns the total number of results for this search.
        *
        * @return the total number of results for this search.
        */
       public final native int getTotalResults() /*-{
       return this.total;
       }-*/;
    
       /**
        * Returns the entry results of the search.
        *
        * @return the entry results of the search.
        */
       public final native MyStatus[] getResults() /*-{
       return this.entries;
       }-*/;
    }