Announcement

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

    TreeGrid ClassCastException in 1.1?

    I've noticed a problem in the TreeGrid, since I upgraded to smartgwt-1.1.

    I couldn't find any troubles in the Showcase, so I've isolated the problem I'm having into the following code snippets:

    Code:
    public class TreeGridDemo implements EntryPoint {
    
      public void onModuleLoad() {
        createTreeGrid().draw();
      }
    
      private TreeGrid createTreeGrid() {
        TreeGrid treeGrid = new TreeGrid();
        treeGrid.setLeaveScrollbarGap(true);
        treeGrid.setLoadDataOnDemand(false);
        treeGrid.setWidth(500);
        treeGrid.setHeight(400);
        treeGrid.setShowOpenIcons(false);
        treeGrid.setShowDropIcons(false);
        treeGrid.setClosedIconSuffix("");
        treeGrid.setAutoFetchData(true);
        treeGrid.setFields(new TreeGridField("caption", "Book Catalog"));
        treeGrid.setDataSource(CatalogDS.getInstance());
        return treeGrid;
      }
    
    }
    The data for my TreeGrid is coming from the server via GwtRpcDataSource, but for the sake of simplicity, this is a simulation without RPC calling involved:

    Code:
    public class CatalogDS extends GwtRpcDataSource {
    
      private static CatalogDS instance = null;
    
      public static CatalogDS getInstance() {
        if (instance == null) {
          instance = new CatalogDS();
        }
        return instance;
      }
    
      public CatalogDS() {
    
        setID("CatalogDS");
        setTitleField("Caption");
        DataSourceTextField captionField = new DataSourceTextField("caption", "Caption");
    
        DataSourceTextField keyField = new DataSourceTextField("key", "Key");
        keyField.setPrimaryKey(true);
        keyField.setRequired(true);
    
        DataSourceTextField parentKeyField = new DataSourceTextField("parentKey", "Parent Key");
        parentKeyField.setRequired(true);
        parentKeyField.setForeignKey("CatalogDS.key");
        parentKeyField.setRootValue("catalogRoot");
    
        setFields(captionField, keyField, parentKeyField);
    
      }
    
      @Override
      protected void executeAdd(String requestId, DSRequest request, DSResponse response) {
        // not supported
      }
    
      @Override
      protected void executeFetch(String requestId, DSRequest request, DSResponse response) {
        ListGridRecord[] data = createTestData();
        response.setData(data);
        response.setTotalRows(data.length);
        response.setStatus(RPCResponse.STATUS_SUCCESS);
        processResponse(requestId, response);
      }
    
      @Override
      protected void executeRemove(String requestId, DSRequest request, DSResponse response) {
        // not supported
      }
    
      @Override
      protected void executeUpdate(String requestId, DSRequest request, DSResponse response) {
        // not supported
      }
    
      private static ListGridRecord[] createTestData() {
        ListGridRecord[] records = new ListGridRecord[6];
        records[0] = createCatalogRecord("catalogRoot", "", "Book Catalog");
        records[1] = createCatalogRecord("author1", "catalogRoot", "Enrique Vila-Matas");
        records[2] = createCatalogRecord("book1", "author1", "Montano's Malady");
        records[3] = createCatalogRecord("author2", "catalogRoot", "Thomas Bernhard");
        records[4] = createCatalogRecord("book2", "author2", "Extinction");
        records[5] = createCatalogRecord("book3", "author2", "Old Masters");
        return records;
      }
    
      private static ListGridRecord createCatalogRecord(String key, String parentKey, String caption) {
        ListGridRecord record = new ListGridRecord();
        record.setAttribute("key", key);
        record.setAttribute("parentKey", parentKey);
        record.setAttribute("caption", caption);
        return record;
      }
    
    }
    These two pieces of code run perfectly on smartgwt-1.0b2 (see attached screenshot).

    With smartgwt-1.1 I get the following exception:
    Code:
    java.lang.ClassCastException: com.smartgwt.client.widgets.grid.ListGridRecord
    	at com.smartgwt.client.widgets.tree.TreeNode.getOrCreateRef(TreeNode.java:69)
    	at com.smartgwt.client.widgets.BaseWidget.draw(Native Method)
    	at org.demos.client.TreeGridDemo.onModuleLoad(TreeGridDemo.java:11)
    What exactly is happening here?
    Thanks!
    Attached Files

    #2
    help, anyone?

    Comment


      #3
      You could have the data be TreeNode instances instead of ListGridRecord. Having said that, SVN has been updated to accept ListGridRecord's as well so your original sample should work fine now.

      PS : Please give it 3 - 5 days before bumping a thread. Yesterday was a holiday for many in the US. If you need priority support with faster response times, you can sign up for a commercial support plan.

      Comment

      Working...
      X