Announcement

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

    Problem caching data with RestDataSource

    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:
    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
    Last edited by deepfriedbrain; 8 Jun 2011, 12:18.

    #2
    That's the right setting for this, but it looks like you may be running in Chrome Hosted Mode (never do this - see FAQ). If not, please provide all the usual details of what version you're testing with what browser on what OS.

    Also, this may or may not be part of the problem, but you have no reason to use RestDataSource here since you're defining a custom format, and should start from DataSource instead.

    Comment


      #3
      Hello Isomorphic,

      Thanks for your response.

      The problem exists on IE8 too, though the error message looks a bit different (see below). I already mentioned the version number and other details in the OP above, but let me put it here again:

      SmartGWT LGPL 2.5 Mar 01, 2011 Nightly Build
      Windows XP SP3
      IE 8, Chrome 11.0.696.71

      Let me also explain what I'm trying to achieve. My requirement is to "not" expose the entire xml file to the client. Earlier I was using DataSource and the xml file was accessed directly from the client. Everything worked fine with that setup. But users can directly access .xml file. Now I moved the xml file loading to the server but found that for every operation on the datasource, a server round trip is made to get the entire xml file from the server. Therefore, I was trying to use caching on the datasource.

      I followed the showcase example of RestDataSource to "Fetch" the file contents from the server. I'm not sure how to get it working with DataSource.

      It would be great if you could guide me towards the right approach.

      Thanks.

      Error on IE8:
      Code:
      12:27:18.983 [ERROR] [testrestds] 12:27:18.968:TMR3:WARN:Log:Error:
          'Object doesn't support this property or method'
          in http://127.0.0.1:8888/testrestds/sc/modules/ISC_DataBinding.js
          at line 2197
          RestDataSource.transformResponse(_1=&gt;Obj, _2=&gt;Obj, _3=&gt;Obj)
          DataSource.$38b(_1=&gt;Obj, _2=&gt;Obj, _3=&gt;Obj, _4=&gt;Obj, _5=&gt;Obj)
          DataSource.$50e(_1=&gt;Obj, _2=&gt;Obj, _3=&gt;Obj)
          [c]Class.fireCallback(_1=&gt;Obj, _2=&gt;&quot;rpcResponse,data,rpcRequest&quot;, _3=&gt;Array[3], _4=&gt;[RestDataSource ID:testDS], _5=&gt;undef) on [Class RPCManager]
          Class.fireCallback(_1=&gt;Obj, _2=&gt;&quot;rpcResponse,data,rpcRequest&quot;, _3=&gt;Array[3], _4=&gt;undef)
          [c]RPCManager.__fireReplyCallback(_1=&gt;Obj, _2=&gt;Obj, _3=&gt;Obj, _4=&gt;Obj)
          [c]RPCManager.fireReplyCallbacks(_1=&gt;Obj, _2=&gt;Obj)
          [c]RPCManager.performOperationReply(_1=&gt;Obj, _2=&gt;Obj)
          [c]RPCManager.$39d(_1=&gt;0)
          ** recursed on [c]Class.fireCallback
      
      com.smartgwt.client.core.JsObject$SGWT_WARN: 12:27:18.968:TMR3:WARN:Log:Error:
          'Object doesn't support this property or method'
          in http://127.0.0.1:8888/testrestds/sc/modules/ISC_DataBinding.js
          at line 2197
          RestDataSource.transformResponse(_1=&gt;Obj, _2=&gt;Obj, _3=&gt;Obj)
          DataSource.$38b(_1=&gt;Obj, _2=&gt;Obj, _3=&gt;Obj, _4=&gt;Obj, _5=&gt;Obj)
          DataSource.$50e(_1=&gt;Obj, _2=&gt;Obj, _3=&gt;Obj)
          [c]Class.fireCallback(_1=&gt;Obj, _2=&gt;&quot;rpcResponse,data,rpcRequest&quot;, _3=&gt;Array[3], _4=&gt;[RestDataSource ID:testDS], _5=&gt;undef) on [Class RPCManager]
          Class.fireCallback(_1=&gt;Obj, _2=&gt;&quot;rpcResponse,data,rpcRequest&quot;, _3=&gt;Array[3], _4=&gt;undef)
          [c]RPCManager.__fireReplyCallback(_1=&gt;Obj, _2=&gt;Obj, _3=&gt;Obj, _4=&gt;Obj)
          [c]RPCManager.fireReplyCallbacks(_1=&gt;Obj, _2=&gt;Obj)
          [c]RPCManager.performOperationReply(_1=&gt;Obj, _2=&gt;Obj)
          [c]RPCManager.$39d(_1=&gt;0)
          ** recursed on [c]Class.fireCallback
          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.BrowserChannelServer.reactToMessagesWhileWaitingForReturn(BrowserChannelServer.java:326)
          at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:207)
          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.invokeNativeVoid(ModuleSpace.java:289)
          at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeVoid(JavaScriptHost.java:107)
          at com.smartgwt.client.data.DataSource.transformResponse(DataSource.java)
          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.reactToMessagesWhileWaitingForReturn(BrowserChannelServer.java:326)
          at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:207)
          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)

      Comment


        #4
        Sorry you've basically lost us on what you're trying to achieve. The QuickStart Guide's Data Integration chapter explains in brief how a DataSource can be configured to work with a pre-existing data format, then links to a deeper discussion that goes into more details.

        Comment


          #5
          I went through the relevant sections of the Quick Start guide. I switched to using DataSource as you suggested in the first post. Moreover, the data format is not rigid and can be changed if need be.

          After switching to DataSource, the problem has changed.

          Now I do "not' get any exception, but the fetch doesn't work at all if I call setCacheAllData(true) on the data source.

          If I remove setCacheAllData(true) call, the fetch works but caching doesn't (data is fetched from the server each time fetchData is called).

          So, in summary, I still cannot get the caching to work with DataSource. Am I misunderstanding the way caching is supposed to work?

          Here's the updated TestXMLDS.java:

          Code:
          package com.dfb.test.client;
          
          import com.smartgwt.client.data.DataSource;
          import com.smartgwt.client.data.OperationBinding;
          import com.smartgwt.client.data.fields.DataSourceTextField;
          import com.smartgwt.client.types.DSOperationType;
          import com.smartgwt.client.types.DSProtocol;
          
          public class TestXMLDS extends DataSource {
          
              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);
          
                  setDataURL("/testrestds/fetchdata");
              }
          }
          Thanks for your patience and help.
          Last edited by deepfriedbrain; 8 Jun 2011, 23:36.

          Comment


            #6
            First, your requirements don't really make sense - if the user loads the file, whether it's via cacheAllData or not, they have the file. There's no way to get the data to the browser and have the user not have the XML of the data.

            Second, your new test case just doesn't call setCacheAllData(true), which is the problem.

            Comment


              #7
              Hello Isomorphic,

              1. The "requirement" is simple - I want to hide the file and its contents from direct access of the users (client). The contents should only be exposed through the application (using list grids and other UI elements).

              But the "solution" may not be the best or even correct in the first place. That's the real problem, and that's where I need some help.

              Currently, the XML file is directly accessible to the client. So, I went one (small) step further:

              a. I put security constraints on the folder that contains the XML file, so that users cannot access it through the URL directly.
              b. Read the file on the server and send the "contents" to the client. This way the file isn't stored on user's file system.

              But as you rightly said, the "content" is still exposed to the client. Anyone using a browser tool like Firebug can still see the file "content" in its entirety. This isn't an ideal solution, but slightly better than what I have today.

              In my view, a better approach would be to parse the file into Java objects, send the objects back from the server and tie them to the datasource. This way users would neither have direct access to the file, nor would they see the file "content" in its entirety. Is it possible to achieve this?

              Is there a better solution to meet the requirements? I'm open to do it any way that you suggest.

              2. My test case does call setCacheAllData(true). It's the first call in the onModuleLoad() inside TestRestDS.java. Please refer to that class in my first post. I could have put it inside TestXMLDS also. Sorry for doing this in a convoluted manner.

              Thanks.
              Last edited by deepfriedbrain; 9 Jun 2011, 07:44.

              Comment


                #8
                Hello Isomorphic,

                Is there any update on this?

                Requirements aside, can you help me understand why setCacheAllData(true) doesn't work in my test case?

                Thanks.

                Comment


                  #9
                  Hi,

                  Can you at least clarify whether it's a SmartGWT issue or something wrong with the test case (incorrect, invalid, not supported etc.)? I'm not asking for a fix or a solution, but just a clarification.

                  You said,
                  Second, your new test case just doesn't call setCacheAllData(true), which is the problem.
                  and I clarified that my test case does indeed call setCacheAllData(true). So, what's really the issue?

                  Thanks.

                  Comment


                    #10
                    There's no way to meaningfully fulfilled this requirement. All the ways of transferring data are going to lead to readable text in Firebug or other tools. Even if you took the trouble to encrypt and decrypt the data, ~5 lines of JavaScript would be required to dump the contents of the grid in the running application.

                    This is basically not something to spend effort on. You can only control a user's permanent access to data if you control the device all the way to the screen (eg a kiosk), even then, the user can just snap a photo and walk away.

                    We don't really follow how the code is meant to be combined to create a runnable test case, but if you're still trying to do something with this feature (it may not be relevant any more), please put together a complete test case so there's no ambiguity.

                    Comment


                      #11
                      Hi,

                      Here's the complete standalone test case again. Please ignore all the code in the previous posts. Also note that setCacheAllData(true) is the first call in onModuleLoad() inside TestDS.java.

                      Here's the problem description:

                      1. After I changed from RestDataSource to DataSource, I do "not" get any exception.
                      2. With setCacheAllData(true) call on the data source, the fetch doesn't work at all.
                      3. If I remove setCacheAllData(true) call, the fetch works, but caching doesn't (i.e. data is fetched from the server each time fetchData is called).


                      TestXMLDS.java
                      Code:
                      package com.dfb.test.client;
                      
                      import com.smartgwt.client.data.DataSource;
                      import com.smartgwt.client.data.OperationBinding;
                      import com.smartgwt.client.data.fields.DataSourceTextField;
                      import com.smartgwt.client.types.DSOperationType;
                      import com.smartgwt.client.types.DSProtocol;
                      
                      public class TestXMLDS extends DataSource {
                      
                          private static TestXMLDS instance = null;
                      
                          public static TestXMLDS getInstance() {
                              if (instance == null) {
                                  instance = new TestXMLDS("testXMLDS");
                              }
                              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);
                      
                              setDataURL("/testds/fetchdata");
                          }
                      }

                      TestDS.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 TestDS implements EntryPoint {
                      
                          public final TestXMLDS testXMLDS = TestXMLDS.getInstance();        
                      
                          public void onModuleLoad() {
                      
                              testXMLDS.setCacheAllData(true); // <-- this is NOT working as expected
                      
                              VLayout rootLayout = new VLayout();
                              rootLayout.setPadding(20);
                              rootLayout.setMembersMargin(20);
                                      
                              final ListGrid grid = new ListGrid();  
                              grid.setWidth(200);  
                              grid.setHeight(300);  
                              grid.setDataSource(testXMLDS);
                      
                              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();      
                      
                          }
                      }
                      TestServiceImpl.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 TestServiceImpl 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>

                      Servlet mapping in web.xml:

                      Code:
                        <!-- Servlets -->
                        <servlet>
                          <servlet-name>fetchService</servlet-name>
                          <servlet-class>com.dfb.test.server.TestServiceImpl</servlet-class>
                        </servlet>
                      
                        <servlet-mapping>
                          <servlet-name>fetchService</servlet-name>
                          <url-pattern>/testds/fetchdata</url-pattern>
                        </servlet-mapping>
                      Thanks.

                      Comment


                        #12
                        Can you clarify:

                        1. what version is this against

                        2. does this occur for all browsers

                        3. what do you mean by "the fetch doesn't work at all"? No fetch issued? JS error? Fetch completed but data doesn't populate? Something else?

                        4. you mention an Exception - please clarify in what circumstances it happens and show the Exception itself. If it's a JavaScript error please show the stack trace.

                        Finally, just a note that we don't need a servlet and servlet mapping for a test case like this, it's a better test to just save the file under webroot and point at it.

                        Comment


                          #13
                          Also, if you switch to RestDataSource, the format of test.data.xml is no longer what the DataSource expects, so this should crash.

                          So please clarify, in addition to the prior questions, are you report a crash with *DataSource* as the class, and are you saying it occurs only when you enable cacheAllData?

                          Comment


                            #14
                            Hi,

                            1. a. Version: SmartGWT LGPL 2.5 Mar 01, 2011 Nightly Build

                            b. OS: Windows XP SP3

                            c. Browser: IE 8, FF 4, Chrome 11.0.696.71

                            2. I've confirmed the problem on both IE 8, FF 4 and Chrome 11x.

                            3. The fetch command is not issued at all. So, nothing is fetched back. There's no JS error or any other kind of error in the firebug console.

                            4. Please refer to the very first post of this thread where I posted the exception details too in that post. I got the exception when I was using "RestDataSource" class. After you told me to use Data Source, I didn't get the exception again. I'm not using RestDataSource at all. So, it is not a part of the problem anymore.

                            After I switched to "DataSource" class, I do "not" get any crash or exception. It's just that when I use setCacheAllData(true) call on the data source, the fetch is not issued and nothing is fetched into the grid. If I remove setCacheAllData(true) call, the fetch works, but caching doesn't (i.e. data is fetched from the server each time fetchData is called).

                            I hope I've clarified all the questions that you asked. Let me know if I've missed something.

                            Thanks.

                            Comment


                              #15
                              Your build pre-dates fixes in this area, please try with the latest nightly.

                              Comment

                              Working...
                              X