Announcement

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

    Record cannot be cast to ListGridRecord?

    I'm trying to populate a client only datasource and show it in a grid. I create it with new DataSource(), setClientOnly(true), create a DataSourceField and setPrimaryKey(true) then addField() and add a few others. I then create a few new Record() objects and use setAttribute() to set the field values and use DataSource.addData(myRecord) to fill the data source. Finally I define a ListGrid and setDataSource() to my new data source. It all seems to work fine except that the grid shows up empty. So I add grid.setAutoFetchData(true) and I get a series of runtime errors telling me that ...

    java.lang.ClassCastException: com.smartgwt.client.data.Record cannot be cast to com.smartgwt.client.widgets.grid.ListGridRecord

    It seems I have to add ListGridRecords to the data source instead of just Records. If I make that change the data appears. But what if I then want to bind some other type of UI widget to the same data source.

    I thought a DataSource just contains Records, not specifically ListGridRecords. What am I misunderstanding?

    #2
    In a similar case I had to create TreeNodes in my DS instead of Records. Luckily those TreeNodes worked well both in the TreeGrid as well as in the ListGrid. I used one and the same DS to feed both UI widgets (can be seen in the W-SHOP app, see below)

    Ekki

    * GWT Rocks! * SmartGWT Rocks Even Harder! * SmartGWT PRO 2.1,
    GWT 2.0, Jetty 7.0.0, Eclipse 3.5.1, JRE 1.6.0_16 *
    For Evaluation only: MySQL 5.1.41, Connector/J 5.1.10

    *** www.EasternGraphics.com/X-4GPL ***

    Comment


      #3
      Jay can you indicate what version you were working with and what the full stack trace looked like?

      Comment


        #4
        SmartClient Version: SC_SNAPSHOT-2010-03-03/Enterprise Deployment (built 2010-03-03)

        Code:
        19:58:49.172 [ERROR] [ipgui] Uncaught exception escaped
        java.lang.ClassCastException: com.smartgwt.client.data.Record cannot be cast to com.smartgwt.client.widgets.grid.ListGridRecord
            at com.smartgwt.client.widgets.grid.ListGridRecord.getOrCreateRef(ListGridRecord.java:90)
            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.BrowserChannel.reactToMessagesWhileWaitingForReturn(BrowserChannel.java:1713)
            at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:165)
            at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:120)
            at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:507)
            at com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:264)
            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:188)
            at sun.reflect.GeneratedMethodAccessor185.invoke(Unknown Source)
            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.BrowserChannel.reactToMessages(BrowserChannel.java:1668)
            at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:401)
            at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:222)
            at java.lang.Thread.run(Thread.java:637)

        Comment


          #5
          Jay it looks like you may have hit a bug in a nightly, can you upgrade to the official 2.1 release?

          Comment


            #6
            I thought I had the official 2.1 release. Can you tell me where to get the official 2.1 release for the EE version?

            Comment


              #7
              I just experienced the same problem and I verified that the solution proposed works. It's strange in any case that I have to add TreeNodes to the client-only datasource.
              I run SmartGWT 2.2

              Comment


                #8
                I also have the same problem. What's the solution proposed? I haven't understood.

                I work with SmartGWT 2.2, Java 1.6 and GWT 2.0.4, but also I tested with SmartGWT2.1 and It's the same...

                This not compile:
                ListGridRecord[] records = response.getData();

                And this...,
                ListGridRecord[] records = (ListGridRecord[]) response.getData();

                ...throws java.lang.ClassCastException: [Lcom.smartgwt.client.data.Record; cannot be cast to [Lcom.smartgwt.client.widgets.grid.ListGridRecord;

                I used "GWT-RPC Datasource template" proposed here: http://forums.smartclient.com/showthread.php?t=4556

                Can you help me? Thank you so much.

                Code:
                   @Override
                   protected void transformResponse(DSResponse response, DSRequest request, Object data) {
                      if (request.getOperationType() != null) {
                         ListGridRecord[] records = response.getData();
                         switch (request.getOperationType()) {
                         case ADD:
                            if (request.getAttributeAsBoolean(DO_NOT_PROPAGATE) != null && request.getAttributeAsBoolean(DO_NOT_PROPAGATE).equals(Boolean.TRUE)) {
                               response.setStatus(-1);
                            } else if (request.getAttributeAsBoolean(DO_NOT_HANDLE) == null || request.getAttributeAsBoolean(DO_NOT_HANDLE).equals(Boolean.FALSE)) {
                               response.setStatus(-1);
                               executeAdd(records);
                            }
                            break;
                         case FETCH:
                            executeFetch();
                            break;
                         case REMOVE:
                            if (request.getAttributeAsBoolean(DO_NOT_HANDLE) == null || request.getAttributeAsBoolean(DO_NOT_HANDLE).equals(Boolean.FALSE)) {
                               executeRemove(records);
                               response.setStatus(-1);
                            }
                            break;
                         case UPDATE:
                            if (request.getAttributeAsBoolean(DO_NOT_HANDLE) == null || request.getAttributeAsBoolean(DO_NOT_HANDLE).equals(Boolean.FALSE)) {
                               response.setStatus(-1);
                               executeEdit(records, request.getAttributeAsObject(PRE_UPDATE_RECORD));
                            }
                            break;
                
                         default:
                            break;
                         }
                      }
                      super.transformResponse(response, request, data);
                   }

                Comment


                  #9
                  I'm running into this again myself (SmartClient Version: SC_SNAPSHOT-2010-10-03/EVAL Deployment). I am passing around and modifying a RecordList full of Records, but never explicitly casting them as ListGridRecords. It seems to be happening when I use the RecordList to setData on the grid. But it doesn't happen every time and I can't see what is different.

                  I've traced it with debug and all of my code executes without error. Then when the ListGrid is drawn this exception is thrown.
                  Code:
                  16:55:12.659 [ERROR] [ipgui] Uncaught exception escaped
                  java.lang.ClassCastException: com.smartgwt.client.data.Record cannot be cast to com.smartgwt.client.widgets.grid.ListGridRecord
                      at com.smartgwt.client.widgets.grid.ListGridRecord.getOrCreateRef(ListGridRecord.java:92)
                      at com.smartgwt.client.widgets.grid.ListGridRecord.getOrCreateRef(ListGridRecord.java:1)
                      at sun.reflect.GeneratedMethodAccessor44.invoke(Unknown Source)
                      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.GeneratedMethodAccessor29.invoke(Unknown Source)
                      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:680)
                  Last edited by jay.l.fisher; 2 Nov 2010, 14:18.

                  Comment


                    #10
                    I'm able to recreate the problem. Here is the sequence of events. I call fetchData on a data source and in the callback I save the response.getDataAsRecordList() into a variable. I then use that variable to setData() on a ListGrid. All is fine until I attempt to add to the RecordList. In my case, I process the results of fetchData() and conditionally add or update the Records in it before I the use it to setData() on the ListGrid.

                    How should I do that? As it is I'm just creating a Record and adding it to the RecordList. Do I have create a ListGridRecord instead?

                    Comment


                      #11
                      Hi Jay,
                      Yes, if you are working with underlying data objects to apply to a ListGrid, you need to work with ListGridRecord rather than Record objects.
                      Let us know if you can't get it working
                      Thanks

                      Comment


                        #12
                        To start with, on the original DataSource.fetchData() callback, how do I get the response data as a RecordList of ListGridRecords? There are only response.getData() and response.getDataAsRecordList() and both of these return collections of Records, not ListGridRecords? I've tried casting and I get the same error.

                        Comment


                          #13
                          You should be able to do this: new ListGridRecord(someRecord.getJsObj());

                          Comment


                            #14
                            That did it, thanks.

                            Comment


                              #15
                              Hi, I seem to have some problems trying to cast Record into ListGridRecord.

                              I have tried this on the following Released Versions of SmartGWT + GWT 2.0.3
                              - 2.2 (May, 2010)
                              - 2.4 (Jan, 2011)

                              This seems to be a client side issue where I am getting the same exception message when I try to do the following:

                              Code:
                              Record[] codecRecords = response.getData([0].getAttributeAsRecordArray("codecs");
                              
                              ListGridRecord[] gridRecords = new ListGridRecord[codecRecords.length];
                              if (codecRecords != null) {
                              for (int x = 0; x < codecRecords.length; x++) {
                              	gridRecords[x] = new ListGridRecord(codecRecords[x].getJsObj());	}
                              }
                              
                              listGrid.setRecords(gridRecords);

                              java.lang.ClassCastException: com.smartgwt.client.data.Record cannot be cast to com.smartgwt.client.widgets.grid.ListGridRecord
                              at com.smartgwt.client.widgets.grid.ListGridRecord.getOrCreateRef(ListGridRecord.java:94)
                              at sun.reflect.GeneratedMethodAccessor53.invoke(Unknown Source)
                              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.BrowserChannel.reactToMessagesWhileWaitingForReturn(BrowserChannel.java:1713)

                              Thank you for your help in advanced.
                              Last edited by howardxchen; 6 Jan 2011, 11:04.

                              Comment

                              Working...
                              X