I'm trying to read an XML file from the server using a RestDataSource. I get a JavaScriptException when I call setCacheAllData(true) on the Rest data source. I'm not sure what the problem is. I've created a simple standalone test case to reproduce the problem.
In the test case, if I click on "Load Data" button, fetchData() is called to fetch the data from the server and the objects are displayed in the grid. If I click on "Clear Data" button, data is cleared from the grid.
I want to cache the data on the client side so that when "Load Data" is clicked subsequently, data is retrieved from the client-side cache and server trip is avoided. To do this, I added the setCacheAllData() call. But, I get the JavaScriptException on the setCacheAllData() call. Without this call, I get the data in the grid, but a server trip is made on each fetchData() call.
So, what is the right way to achieve client side caching? Following are the exception details and the complete standalone test example to reproduce the problem.
I'm using SmartGWT 2.5 LGPL 3/1 nightly build on Chrome 11x / Windows XP SP3.
Exception:
TestRestDS.java
TestXMLDS.java
RestServiceImpl.java
test.data.xml
Thanks
In the test case, if I click on "Load Data" button, fetchData() is called to fetch the data from the server and the objects are displayed in the grid. If I click on "Clear Data" button, data is cleared from the grid.
I want to cache the data on the client side so that when "Load Data" is clicked subsequently, data is retrieved from the client-side cache and server trip is avoided. To do this, I added the setCacheAllData() call. But, I get the JavaScriptException on the setCacheAllData() call. Without this call, I get the data in the grid, but a server trip is made on each fetchData() call.
So, what is the right way to achieve client side caching? Following are the exception details and the complete standalone test example to reproduce the problem.
I'm using SmartGWT 2.5 LGPL 3/1 nightly build on Chrome 11x / Windows XP SP3.
Exception:
Code:
03:56:31.828 [ERROR] [testrestds] Uncaught exception escaped com.google.gwt.core.client.JavaScriptException: (TypeError): Object #<Object> has no method 'selectString' stack: TypeError: Object #<Object> has no method 'selectString' at Object.isc_RestDataSource_transformResponse [as __transformResponse] (http://127.0.0.1:8888/testrestds/sc/modules/ISC_DataBinding.js:2197:171) at [object Object].<anonymous> (unknown source) at __gwt_jsInvoke (http://127.0.0.1:8888/testrestds/hosted.html?testrestds:76:35) at eval at <anonymous> (http://127.0.0.1:8888/testrestds/hosted.html?testrestds:54:12) at Object.<anonymous> (unknown source) at unknown source at __gwt_jsInvoke (http://127.0.0.1:8888/testrestds/hosted.html?testrestds:76:35) at eval at <anonymous> (http://127.0.0.1:8888/testrestds/hosted.html?testrestds:54:12) at Object.transformResponse (unknown source) at Object.isc_DataSource__completeResponseProcessing [as $38b] (http://127.0.0.1:8888/testrestds/sc/modules/ISC_DataBinding.js:529:27) arguments: selectString,[object Object] type: undefined_method __gwt_ObjectId: 102 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.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.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.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:662)
TestRestDS.java
Code:
package com.dfb.test.client; import com.google.gwt.core.client.EntryPoint; 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.grid.ListGridRecord; import com.smartgwt.client.widgets.layout.VLayout; public class TestRestDS implements EntryPoint { public final TestXMLDS testDS = TestXMLDS.getInstance(); public void onModuleLoad() { testDS.setCacheAllData(true); // <-- this results in the exception VLayout rootLayout = new VLayout(); rootLayout.setPadding(20); rootLayout.setMembersMargin(20); final ListGrid grid = new ListGrid(); grid.setWidth(200); grid.setHeight(300); grid.setDataSource(testDS); IButton button1 = new IButton("Load data"); button1.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { grid.fetchData(); } }); IButton button2 = new IButton("Clear data"); button2.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { grid.setData(new ListGridRecord[] {}); } }); ListGridField field = new ListGridField("name", "Name"); grid.setFields(field); rootLayout.setMembers(grid, button1, button2); rootLayout.draw(); } }
TestXMLDS.java
Code:
package com.dfb.test.client; import com.smartgwt.client.data.OperationBinding; import com.smartgwt.client.data.RestDataSource; import com.smartgwt.client.data.fields.DataSourceTextField; import com.smartgwt.client.types.DSOperationType; import com.smartgwt.client.types.DSProtocol; public class TestXMLDS extends RestDataSource { private static TestXMLDS instance = null; public static TestXMLDS getInstance() { if (instance == null) { instance = new TestXMLDS("testDS"); } return instance; } public TestXMLDS(String id) { setID(id); setTitleField("name"); setRecordXPath("/List/test"); DataSourceTextField nameField = new DataSourceTextField("name", "Name"); nameField.setPrimaryKey(true); nameField.setRequired(true); setFields(nameField); OperationBinding fetch = new OperationBinding(); fetch.setOperationType(DSOperationType.FETCH); fetch.setDataProtocol(DSProtocol.POSTMESSAGE); setOperationBindings(fetch); setFetchDataURL("/testrestds/restdata"); setClientOnly(false); } }
RestServiceImpl.java
Code:
package com.dfb.test.server; import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; import java.io.PrintWriter; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; public class RestServiceImpl extends HttpServlet { /** * */ private static final long serialVersionUID = 2176453162551858421L; public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { System.out.println("SERVER POST METHOD"); response.setContentType("text/xml"); PrintWriter out = response.getWriter(); out.print(readFile("test.data.xml")); out.flush(); out.close(); } private String readFile( String file ) throws IOException { BufferedReader reader = new BufferedReader( new FileReader (file)); String line = null; StringBuilder stringBuilder = new StringBuilder(); String ls = System.getProperty("line.separator"); while( ( line = reader.readLine() ) != null ) { stringBuilder.append( line ); stringBuilder.append( ls ); } return stringBuilder.toString(); } }
test.data.xml
Code:
<List> <test> <name>name1</name> </test> <test> <name>name2</name> </test> <test> <name>name3</name> </test> <test> <name>name4</name> </test> </List>
Thanks
Comment