Announcement

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

    saveLocally ListGrid problem with 3.1d

    Hi,

    I have a listgrid based editor in my application with saveLocally=true set to allow complex local edit operations. As the grid is edited new records are manually added as local copies and saved afterwards in a custom network operation.

    This approach has worked ok since 2.x branch and a problem appeared with 3.1d. When adding new records to the grid all the pending edits from the grid disappear with these warnings on console:

    Code:
    WARN:Log:findByKeys: passed record does not have a value for key field 'id'
    ListGrid:isc_CommitableRemoveListGrid_2:Record:{__ref: {GWT Java Obj}, otherId: "-110", orderVal: 25, _selection_45: false}, is no longer present in this List.<br>Clearing edit values for this record.
    By looking at the code which discards the edits it seems that the ListGrid below tries to remap the edit rows by a set of fields instead of the primary key (which is by design missing on added rows) - it does not find the record and discards all the edits. When looking at the warning the "otherId" and "orderVal" fields are correct but the "_selection_45_" attribute in the derived "compound primary key" probably messes up the lookup. This attribute is generated automatically somewhere behind the scenes - probably has something to do with list grid's selection tracking.

    Any idea where this _selection_45 attribute comes from and is this a bug in the underlying code ? As far as I understand this attribute should not be a part of the derived set of primary key fields for locally saved "records" without primary key.

    Using 3.1D LGPL nightly NIGHTLY-2012-10-12.

    #2
    We can't tell much from this - it suggests either a bad primaryKey definition, or that you are using multiple primary keys, which is not supported in 3.1 for grid editing, and which may be misfiring in some way with your logic.

    For more help, put together code we can run to see the problem.

    Comment


      #3
      Try this.

      Code:
              viewport = new VLayout();
              viewport.setWidth100();
              viewport.setHeight100();
      
              final DataSource ds = new DataSource();
              DataSourceIntegerField idField = new DataSourceIntegerField("id");
              idField.setPrimaryKey(true);   // this has no effect, error occurs even without primary keys
              idField.setHidden(true);
              DataSourceTextField textField = new DataSourceTextField("text");
              ds.setFields(idField, textField);
      
              final ListGrid grid = new ListGrid();
              grid.setSize("400", "400");
      
              grid.setAutoSaveEdits(false);
              grid.setDataSource(ds);
              grid.setAutoFetchData(false);
              grid.setSaveLocally(true);
      
              grid.setCanEdit(true);
              grid.setEditByCell(false);
              grid.setListEndEditAction(RowEndEditAction.NEXT);
      
              Button button = new Button("add row");
              button.addClickHandler(new ClickHandler() {
                  @Override
                  public void onClick(ClickEvent event) {
                      Record r = new Record();
                      r.setAttribute("text", "test text");
                      grid.addData(r);
                  }
              });
      
              viewport.addMember(grid);
              viewport.addMember(button);
              viewport.draw();
      How to reproduce:

      1. add some records to grid by clicking "add row"
      2. click a row, edit it
      3. click "add row"

      Comment


        #4
        Your DataSource has no primaryKey and this is required for ListGrid editing.

        Comment


          #5
          idField is set as a primary key, please see the code.

          Or do you mean that all the records must have a primary key set for this to work ? I'm pretty sure this has worked without in earlier smartgwt versions.

          --
          Marko

          Comment


            #6
            Yes, primaryKey field is set, but the record you have added (via addData()) has no value for primaryKey - it's invalid.

            Comment


              #7
              Thanks! I go around this by generating temporary primary keys.

              Comment

              Working...
              X