Hello,
I'am trying to use DataSource.setUseOfflineStorage().
Data seems to be cached correctly under Local Storage, but when the application goes offline, the following exceptioin is thrown:
Minimal example:
Dummy datasource:
Steps to reproduce:
I'am trying to use DataSource.setUseOfflineStorage().
Data seems to be cached correctly under Local Storage, but when the application goes offline, the following exceptioin is thrown:
Code:
ISC_Core.js:1225 *10:56:38.392:TMR5:WARN:Log:Uncaught exception escaped: com.google.gwt.core.client.JavaScriptException (TypeError) : self_0_g$.__useOfflineResponse is not a function at Hi_g$(dummyModule-0.js@31:25000) at <anonymous>(dummyModule-0.js@22:24256) at aU_g$(dummyModule-0.js@28:4492) at dU_g$(dummyModule-0.js@16:4548) at useOfflineResponse(dummyModule-0.js@14:4528) at isc_DataSource_fulfilledFromOffline(http://127.0.0.1:8888/dummyModule/sc/modules/ISC_DataBinding.js@461:606) at isc_DataSource_getServiceInputs(http://127.0.0.1:8888/dummyModule/sc/modules/ISC_DataBinding.js@599:349) at isc_DataSource_sendDSRequest(http://127.0.0.1:8888/dummyModule/sc/modules/ISC_DataBinding.js@14:589) at isc_DataSource_performDSOperation(http://127.0.0.1:8888/dummyModule/sc/modules/ISC_DataBinding.js@13:561) at isc_DataSource_fetchData(http://127.0.0.1:8888/dummyModule/sc/modules/ISC_DataBinding.js@99:519) at isc_ResultSet_fetchRemoteData(http://127.0.0.1:8888/dummyModule/sc/modules/ISC_DataBinding.js@88:1402) at isc_ResultSet__fetchRemoteData(http://127.0.0.1:8888/dummyModule/sc/modules/ISC_DataBinding.js@588:1397) at isc_c_Class_fireCallback(http://127.0.0.1:8888/dummyModule/sc/modules/ISC_Core.js@104:300) at isc_c_Class__fireActionsOnPause(http://127.0.0.1:8888/dummyModule/sc/modules/ISC_Core.js@383:305) at isc_c_Class_fireCallback(http://127.0.0.1:8888/dummyModule/sc/modules/ISC_Core.js@104:300) at isc_c_Timer__fireTimeout(http://127.0.0.1:8888/dummyModule/sc/modules/ISC_Core.js@166:1793) at anonymous(http://127.0.0.1:8888/dummyModule/sc/modules/ISC_Core.js@40:1790) [...] ISC_Core.js:1225 *10:56:38.401:TMR5:WARN:ResultSet:isc_ResultSet_0 (dataSource: isc_RestDataSource_0, created by: isc_ListGrid_0):Bad data returned, ignoring: "This data not available while offline"
Code:
import com.google.gwt.core.client.EntryPoint; import com.smartgwt.client.data.RestDataSource; import com.smartgwt.client.util.Offline; import com.smartgwt.client.widgets.Canvas; import com.smartgwt.client.widgets.IButton; import com.smartgwt.client.widgets.events.ClickEvent; import com.smartgwt.client.widgets.events.ClickHandler; import com.smartgwt.client.widgets.grid.ListGrid; import com.smartgwt.client.widgets.grid.ListGridField; import com.smartgwt.client.widgets.layout.HLayout; import com.smartgwt.client.widgets.layout.VLayout; public class dummyModule implements EntryPoint { public Canvas getViewPanel() { RestDataSource dummyDS = new RestDataSource(); dummyDS.setDataURL("http://127.0.0.1:8888/dummyData.jsp"); dummyDS.setUseOfflineStorage(true); final ListGrid grid = new ListGrid(); grid.setWidth(400); grid.setHeight(250); grid.setDataSource(dummyDS); ListGridField itemIdField = new ListGridField("itemID"); ListGridField itemNameField = new ListGridField("itemName"); ListGridField unitCostField = new ListGridField("unitCost"); grid.setFields(itemIdField, itemNameField, unitCostField); grid.setAutoFetchData(true); //grid.setCanEdit(true); HLayout hLayout = new HLayout(); hLayout.setMembers(grid); VLayout layout = new VLayout(10); final IButton offonButton = new IButton("Go Offline", new ClickHandler() { @Override public void onClick(ClickEvent event) { final IButton source = (IButton) event.getSource(); if(source.getTitle().equals("Go Offline")) { Offline.goOffline(); source.setTitle("Go Online"); } else { Offline.goOnline(); source.setTitle("Go Offline"); } } }); final IButton reloadButton = new IButton("Reload data", new ClickHandler() { @Override public void onClick(ClickEvent event) { grid.invalidateCache(); } }); layout.setMembers(hLayout, offonButton, reloadButton); layout.setAutoHeight(); return layout; } public void onModuleLoad() { getViewPanel().draw(); } }
Code:
<response> <status>0</status> <startRow>0</startRow> <endRow>2</endRow> <totalRows>3</totalRows> <data> <record><itemID>1</itemID><itemName>Name1</itemName><unitCost>5</unitCost></record> <record><itemID>2</itemID><itemName>Name2</itemName><unitCost>10</unitCost></record> <record><itemID>3</itemID><itemName>Name3</itemName><unitCost>15</unitCost></record> </data> </response>
- Start the application (data appears in the grid correctly, you can check that it is also cached in Local Cache)
- Click Reload button (data is reloaded as expected)
- Click Go offline button
- Click Reload button (the grid is empty and the exception is shown on the console)
Comment