Announcement

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

    Smartgwt Mobile Datasource fetch

    Hi Isomorphic,

    I am trying to fetch data from a datasource into a TableView Widget.

    Here is the datasource definition, stored in the ds directory:

    Code:
    Prueba.xml
    
    <DataSource
        ID="prueba"
        serverType="sql"
        tableName="prueba"
    >
        <fields>
            <field name="pruebaID" type="sequence" title="pruebaID" primaryKey="true" hidden="true"/>
            <field name="nombrePrueba" type="text" title="Nombre"/>
            
        </fields>
        
    </DataSource>
    And here is the code to fetchdata and fiil the tableView:

    Code:
     DataSource.loadDataSource("prueba", new LoadDSCallback() {
    			public void execute(DataSource[] dsList) {
                    // start creating and binding widgets
    				
    				
    				TableView tv = new TableView();
    				tv.setDataSource(dsList[0]);
                    tv.fetchData();
                    
    			}
            });
    I have set the resthandler and datasourceloader servlets in the web.xml as follows:

    [code]

    <servlet>
    <servlet-name>RestHandler</servlet-name>
    <servlet-class>com.isomorphic.servlet.RESTHandler</servlet-class>
    <init-param>
    <param-name>defaultDataFormat</param-name>
    <param-value>json</param-value>
    </init-param>
    <init-param>
    <param-name>wrapJSONResponses</param-name>
    <param-value>false</param-value>
    </init-param>

    </servlet>




    <servlet>
    <servlet-name>DataSourceLoader</servlet-name>
    <servlet-class>com.isomorphic.servlet.DataSourceLoader</servlet-class>
    </servlet>

    <servlet-mapping>
    <servlet-name>RestHandler</servlet-name>
    <url-pattern>/isomorphic/RESTHandler</url-pattern>
    </servlet-mapping>

    <!-- DataSourceLoader requests -->
    <servlet-mapping>
    <servlet-name>DataSourceLoader</servlet-name>
    <url-pattern>/isomorphic/DataSourceLoader</url-pattern>
    </servlet-mapping>

    [code]

    I am using the smartgwt mobile jar file which creation date is May 10th 2012.

    When I try to fetch data I get the following exception:

    Code:
    16:28:50.906 [ERROR] [plantillaIdeiak] Uncaught exception escaped
    
    java.lang.ClassCastException: com.smartgwt.mobile.client.data.Record cannot be cast to com.smartgwt.mobile.client.data.DataSourceField
        at com.smartgwt.mobile.client.data.DataSource.fromConfig(DataSource.java:1580)
        at com.smartgwt.mobile.client.data.DataSource$2.onResponseReceived(DataSource.java:1547)
        at com.google.gwt.http.client.Request.fireOnResponseReceived(Request.java:287)
        at com.google.gwt.http.client.RequestBuilder$1.onReadyStateChange(RequestBuilder.java:395)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        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:172)
        at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessagesWhileWaitingForReturn(BrowserChannelServer.java:337)
        at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:218)
        at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:136)
        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:213)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        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:172)
        at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessages(BrowserChannelServer.java:292)
        at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:546)
        at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:363)
        at java.lang.Thread.run(Unknown Source)
    which it seems that the from config method of the datasource class has a bug on casting a record to a datasourcefield.

    Could please tell me if I am using the datasource load correctly and if its a bug, o otherwise I am doing something wrong?

    Thanks in advance,

    Pablo

    #2
    Hi isomorphic, did you reproduce the problem?

    I think i am doing the configuration and the fetch operation correctly.

    Looking forward your answer and thanks in advance.

    Pablo

    Comment


      #3
      Your code is fine, this was a temporary regression and will be fixed shortly.

      Comment


        #4
        Hi isomorphic,

        I have downloaded the SmartGWT Mobile SDK today (May 30th) and the smartgwtmobile.jar file is still from May 10th.

        When do you expect this bug will be fixed?

        Thanks in advance.

        Pablo

        Comment


          #5
          Hi osomorphic, did you correct the bug on datasource fetch of mobile api?

          Thanks in advance,

          Pablo

          Comment


            #6
            Hi isomorphic, any news about this topic??

            Pablo

            Comment


              #7
              I have the same blocking problem.
              Where can we get a patched SDK if the solution is known?
              Otherwise is there a workaround?

              Thanks

              Comment


                #8
                I tried to help myself by copying the source of DataSource class in my source tree and patching its fromConfig() method as below.
                So now I am able to load a DataSource but then the fetch itself fails I get an exception in client

                com.google.gwt.core.client.JavaScriptException: (SyntaxError): missing } in XML expression

                The reponse body is:
                Code:
                <SCRIPT>//'"]]>>isc_JSONResponseStart>>{"response":{"invalidateCache":false,"isDSResponse":true,"status":-1,"data":null}}//isc_JSONResponseEnd
                My patch of DataSource.fromConfig():

                Code:
                	protected static DataSource fromConfig(String configText) {
                		// Strip off extraneous SmartClient object creation stuff - we just want the config
                		int start = configText.indexOf("{");
                		int end = configText.lastIndexOf("}") + 1;
                		if (start == -1 || end < start)
                			return null;
                		String forEval = configText.substring(start, end);
                		Map<String, Object> config = JSONUtils.toRecord(JSONUtils.evalJSONString(forEval));
                
                		DataSource ds = new DataSource((String) config.get("ID"));
                		@SuppressWarnings("unchecked")
                		List<Record> fields = (List<Record>) config.get("fields");
                		DataSourceField[] dsFields = new DataSourceField[fields.size()];
                		if (fields != null) {
                			for (int i = 0; i < fields.size(); i++) {
                				dsFields[i] = new DataSourceField(fields.get(i));
                			}
                		}
                		@SuppressWarnings("unchecked")
                		List<Record> bindings = (List<Record>) config.get("operationBindings");   // Patch
                		OperationBinding[] operationBindings = null;
                		if (bindings != null) {
                			operationBindings = new OperationBinding[bindings.size()];
                			if (fields != null) {
                				for (int i = 0; i < bindings.size(); i++) {
                					OperationBinding binding = new OperationBinding((bindings.get(i)));  // Patch
                					operationBindings[i] = new OperationBinding(binding);
                				}
                			}
                		}
                
                		for (Map.Entry<String, Object> e : config.entrySet()) {
                			ds.attributes.put(e.getKey(), e.getValue());
                		}
                
                		ds.setFields(dsFields);
                		if (operationBindings != null)
                			ds.setOperationBindings(operationBindings);
                
                		return ds;
                	}

                Comment


                  #9
                  I went further, datasource fetches the data on server but I get an NPE on server when completing the response.
                  This does not happen if I disable the JSON response wrapping in the RESTHandler.


                  Code:
                  java.lang.NullPointerException
                  	at java.io.PrintWriter.write(PrintWriter.java:429)
                  	at com.isomorphic.rpc.RPCManager.completeResponse(RPCManager.java:1272)
                  	at com.isomorphic.rpc.RPCManager.send(RPCManager.java:582)
                  	at com.isomorphic.rpc.RPCManager.sendFailure(RPCManager.java:665)
                  	at com.isomorphic.rpc.RPCManager.sendFailure(RPCManager.java:686)
                  	at com.isomorphic.servlet.IDACall.processRPCTransaction(IDACall.java:162)

                  Comment


                    #10
                    Can you post what the forums asks for, in this case: your exact version, and the complete server log for the request.

                    Comment


                      #11
                      SmartClient Version: v8.2p_2012-04-03/Pro Deployment (built 2012-04-03)

                      And no for the server log, I don't have time to rollback, I'm trying to get a mobile UI to work within days.

                      Why don't you setup a dedicated forum for SGWT mobile and also nightly builds?

                      Comment


                        #12
                        SGWT mobile version: 1.0 06/05/2012 09:30 -0700
                        SGWT 3.0p
                        GWT 2.4
                        Any browser

                        Comment


                          #13
                          We show this problem as corrected a while ago and if you are still experiencing it, it's probably because you copied source files around and still have your own private copies of the classes being used.

                          Comment


                            #14
                            Could you tell me when this was fixed because I haven't used any other version than SGWT mobile version: 1.0 06/05/2012 09:30 -0700 which was the only one available for download at beginning of June.
                            I have removed my patched DataSource and this is still failing.


                            Code:
                            23:57:20.583 [ERROR] [mobile] Uncaught exception escaped
                            
                            java.lang.ClassCastException: com.smartgwt.mobile.client.data.Record cannot be cast to com.smartgwt.mobile.client.data.OperationBinding
                                at com.smartgwt.mobile.client.data.DataSource.fromConfig(DataSource.java:1643)
                                at com.smartgwt.mobile.client.data.DataSource$2.onResponseReceived(DataSource.java:1600)
                                at com.google.gwt.http.client.Request.fireOnResponseReceived(Request.java:287)
                                at com.google.gwt.http.client.RequestBuilder$1.onReadyStateChange(RequestBuilder.java:395)
                                at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                                at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
                                at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
                                at java.lang.reflect.Method.invoke(Unknown Source)
                                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:172)
                                at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessagesWhileWaitingForReturn(BrowserChannelServer.java:337)
                                at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:218)
                                at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:136)
                                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:213)
                                at sun.reflect.GeneratedMethodAccessor36.invoke(Unknown Source)
                                at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
                                at java.lang.reflect.Method.invoke(Unknown Source)
                                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:172)
                                at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessages(BrowserChannelServer.java:292)
                                at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:546)
                                at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:363)
                                at java.lang.Thread.run(Unknown Source)
                            and the response

                            Code:
                            isc.DataSource.create({
                                titleField:"_title",
                                ID:"core:mockapp:structure",
                                pluralTitle:"Structures",
                                dataURL:"mockapp.data",
                                operationBindings:[
                                    {
                                        operationType:"add",
                                        serverMethod:"postProcessStructureDescription"
                                    },
                                    {
                                        operationType:"update",
                                        serverMethod:"postProcessStructureDescription"
                                    },
                                    {
                                        operationType:"fetch",
                                        serverMethod:"postProcessStructureDescription"
                                    }
                                ],
                                fields:[
                                    {
                                        title:"ID",
                                        primaryKey:true,
                                        name:":id",
                                        type:"sequence",
                                        canEdit:false
                                    },
                                    {
                                        title:"Parent",
                                        name:"_parent",
                                        type:"integer",
                                        canEdit:false
                                    },
                                    {
                                        title:"Label",
                                        name:":label",
                                        type:"text",
                                        canEdit:false
                                    },
                                    {
                                        title:"Name",
                                        name:":name",
                                        type:"text",
                                        required:true
                                    },
                                    {
                                        canSave:false,
                                        title:"Title",
                                        name:"_title",
                                        type:"text",
                                        required:false,
                                        canEdit:false
                                    },
                                    {
                                        title:"Fields",
                                        hidden:true,
                                        name:":fields",
                                        type:"core:mockapp:field",
                                        multiple:true
                                    },
                                    {
                                        title:"Views",
                                        hidden:true,
                                        name:":views",
                                        type:"core:mockapp:view",
                                        multiple:true
                                    },
                                    {
                                        title:"Data Source",
                                        name:"_framedDataSource",
                                        type:"text",
                                        canEdit:false
                                    },
                                    {
                                        title:"Represented properties",
                                        name:":representedProperties",
                                        type:"integer",
                                        canEdit:true,
                                        multiple:false
                                    }
                                ],
                                dockName:"STRUCTURES"
                            })

                            Comment


                              #15
                              The release notes show when the fix was put in. Despite your efforts to get rid of your custom DataSource class, it's probably still around somehow.

                              Comment

                              Working...
                              X