Announcement

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

    ListGrid.createRecordComponent () not invoked on first dataSource.addData () call

    I have a DataSource backed ListGrid.
    I override createRecordComponent () to render a cell as a button.
    When the I add the first record via dataSource.addData (), the record is added to the ListGrid, but createRecordComponent () is not called, and no button appears in my cell.
    When I add the second record via dataSource.addData (), the record is added to the ListGrid, and createRecordComponent () is called twice, and now both records show the button.
    When I added record #3, createRecordComponent () is called 3 times, and all records show the button.
    See provided sample and output (Dev Console output section below), showing this.

    Is there something I can do to make this work, or should I open this as a bug?

    Be sure your post includes:

    1. the SmartGWT or SmartClient version and browser version(s) involved;
    GWT 2.0.3 / SmartGWT 2.1
    GWT 2.0.3 / SmartGWT 2.3 build 1397
    Google Chrome 6.0.472.59 beta and IE 6.0.2900.5512

    2. for a server-side problem, the complete logs generated during processing of the request;
    N/A

    3. for a client-side problem, the contents of the Developer Console (see FAQ for usage);
    Code:
    17:51:37.853:INFO:Log:initialized
    17:51:37.869:WARN:Page:NOTE: isc.Page.getWidth() called before <BODY> tag was written out -- value cannot be determined.  Returning 500
    17:51:37.869:WARN:Page:NOTE: isc.Page.getHeight() called before <BODY> tag was written out -- value cannot be determined.  Returning 500
    17:51:38.072:WARN:AutoObserver:Use addInterfaceProperties() to add methods to interface [Class AutoObserver]
    17:51:38.400:INFO:Log:isc.Page is loaded
    Dev Console output
    Code:
    02:23:51.984 [INFO] Loading module portal
    02:23:57.219 [INFO] Module portal has been loaded
    02:24:03.281 [INFO] Add Record button pressed: adding record #1
    02:24:06.422 [INFO] Add Record button pressed: adding record #2
    02:24:06.500 [INFO] createRecordComponent (colNum: 0): fieldName: name
    02:24:06.516 [INFO] createRecordComponent (colNum: 1): fieldName: button
    02:24:06.609 [INFO] createRecordComponent (colNum: 0): fieldName: name
    02:24:06.625 [INFO] createRecordComponent (colNum: 1): fieldName: button
    02:24:09.625 [INFO] Add Record button pressed: adding record #3
    02:24:09.734 [INFO] createRecordComponent (colNum: 0): fieldName: name
    02:24:09.750 [INFO] createRecordComponent (colNum: 1): fieldName: button
    02:24:09.812 [INFO] createRecordComponent (colNum: 0): fieldName: name
    02:24:09.828 [INFO] createRecordComponent (colNum: 1): fieldName: button
    02:24:09.891 [INFO] createRecordComponent (colNum: 0): fieldName: name
    02:24:09.906 [INFO] createRecordComponent (colNum: 1): fieldName: button
    4. if there is a JavaScript error, the stack trace logged in the Developer Console (from Internet Explorer if possible); and

    5. sample code.
    Code:
    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.Canvas;
    import com.smartgwt.client.widgets.IButton;
    import com.smartgwt.client.widgets.layout.VLayout;
    import com.smartgwt.client.widgets.events.ClickHandler;
    import com.smartgwt.client.widgets.events.ClickEvent;
    import com.smartgwt.client.data.fields.DataSourceImageField;
    import com.smartgwt.client.data.fields.DataSourceTextField;
    import com.smartgwt.client.data.SortSpecifier;
    import com.smartgwt.client.data.Record;
    import com.smartgwt.client.data.DataSource;
    import com.smartgwt.client.types.Autofit;
    import com.smartgwt.client.types.SortDirection;
    import com.smartgwt.client.util.SC;
    
    import com.google.gwt.core.client.EntryPoint;
    import com.google.gwt.core.client.GWT;
    
    /**
     *
     */
    public class TestListGridCreateRecordComponent implements EntryPoint {
    
      // my classes
      public static class MyListGrid extends ListGrid {
    
        // my constants
        private static interface FieldName {
          String ID = "id";
          String NAME = "name";
          String BUTTON = "button";
        }
      
        // my classes
        private static class DataGridDataSource extends DataSource {
      
          DataGridDataSource () {
      
            // mark as client only or we get exceptions indicating the server is missing
            setClientOnly (true);
      
            // create fields
            final DataSourceTextField addressField = new DataSourceTextField (FieldName.ID);
            addressField.setPrimaryKey (true);
            addressField.setRequired (true);
            addField (addressField);
            addField (new DataSourceTextField (FieldName.NAME));
            addField (new DataSourceImageField (FieldName.BUTTON));
          }
        }
      
        // my variables
        private final DataGridDataSource dataSource = new DataGridDataSource ();
      
        /**
         * Initializes this control
         */
        public void initialize () {
      
          // initialize
          setShowAllRecords (true);
          setAutoFetchData (true);
          setCanEdit (false);
          setAutoFitData (Autofit.BOTH);
          setCanSort (true);
          setCanGroupBy (false);
          setShowRecordComponents (true);         // required to render button
          setShowRecordComponentsByCell (true);   // required to render button
          setSort (new SortSpecifier[] { new SortSpecifier (FieldName.NAME, SortDirection.ASCENDING)});
      
          // setup datasource
          setDataSource (dataSource);
            
          // add fields with reasonable widths
          final ListGridField nameField = new ListGridField (FieldName.NAME, "Name", 150);
          final ListGridField buttonField = new ListGridField (FieldName.BUTTON, "Button", 40);
          setFields (nameField, buttonField);
        }
    
        /**
         * Adds the given Record
         * @param id
         * @param name
         */
        public void addRecord (
          final int id,
          final String name) {
    
          // objectify
          final Record record = new ListGridRecord ();
          record.setAttribute (FieldName.ID, id);
          record.setAttribute (FieldName.NAME, name);
          
          // delegate
          dataSource.addData (record);
        }
      
        /**
         * The ListGrid interface: overridden to render the connection buttons
         * @param record
         * @param colNum
         * @return Canvas
         */
        @Override
        protected Canvas createRecordComponent (
          final ListGridRecord record,
          final Integer colNum) {
      
          // fieldName-specific processing
          final String fieldName = getFieldName (colNum);
          GWT.log ("createRecordComponent (colNum: " + colNum + "): fieldName: " + fieldName);
          if (fieldName.equals (FieldName.BUTTON)) {
      
            // add a button
            final IButton button = new IButton ();
            button.setHeight (18);
            button.setWidth (24);
            button.setIcon ("images/action_stop.gif");
            button.setTitle ("");
            button.addClickHandler (new ClickHandler () {
              public void onClick (final ClickEvent event) {
    
                // delegate
                SC.say ("Hello!");
              }
            });
            return button;
          }
      
          // no control to set -- note that neither the documentation nor the samples indicate whether
          // we should return null or super.createRecordComponent ()!
          return null;
        }
      }
    
      /**
       * The EntryPoint interface
       */
      public void onModuleLoad () {
    
        // show the dev console immediately
        SC.showConsole ();
        
        // create the list grid
        final MyListGrid listGrid = new MyListGrid ();
        listGrid.initialize ();
        
        // create a button to add records
        final IButton addRecordButton = new IButton ();
        {
          addRecordButton.setAutoFit (true);
          addRecordButton.setTitle ("Add record");
          addRecordButton.addClickHandler (new ClickHandler () {
            int nextId = 0;
            public void onClick (final ClickEvent event) {
    
              nextId ++;
              GWT.log ("Add Record button pressed: adding record #" + nextId);
              listGrid.addRecord (nextId, "Record #" + nextId);
            }
          });
        }
        
        // display
        final VLayout layout = new VLayout ();
        layout.setWidth100 ();
        layout.setHeight100 ();
        layout.setLayoutMargin (5);
        layout.addMember (listGrid);
        layout.addMember (addRecordButton);
        layout.draw ();
      }
    }
    Posts with incomplete information are much more likely to be ignored.

    #2
    Since this happens 100% of the time, I opened this:
    http://code.google.com/p/smartgwt/issues/detail?id=513

    Comment

    Working...
    X