Announcement

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

    ClientOnly DataSource for ListGrid with duplicate primary keys

    Hi, I'm using v9.1p_2015-04-18/PowerEdition Deployment 2015-04-18, the problem explained below occurs within Chrome (Version 46.0.2490.71 m) and Firefox (41.0.2).

    I have a DataSource defined as following:

    Code:
    public OverviewDs() {
            setID("blaid");
            
            DataSourceIntegerField mid = new DataSourceIntegerField("id", "id");
            mid.setRequired(true);
            mid.setPrimaryKey(true);
            mid.setCanEdit(false);
            mid.setHidden(true);
            
            DataSourceTextField identity = new DataSourceTextField("iden", "iden");
            identity.setRequired(true);
            identity.setCanEdit(false);
            identity.setHidden(false);
                    
            DataSourceIntegerField occ = new DataSourceIntegerField("occ", "occ");
            occ.setRequired(true);
            occ.setCanEdit(false);
            occ.setHidden(false);
            
            setFields(mid, identity, occ);
            setClientOnly(true);
        }
    I add data via
    Code:
    ListGrid myListGrid = new ListGrid();
    myListGrid.setAutoFetchData(false);
    
    DataSource ds = new OverviewDs();
    int count = 0;
    for (Items i : lotsOfItems) {
      count++;
      // create ListGridRecord with id set to count
      ds.addData(generatedListGridRecord);
    }
    myListGrid.setDataSource(ds);
    myListGrid.fetchData();
    the "lotsOfItems" are around 200, I verified that on my end the primary key is unique and added only once. When I view the data and inspect the list I see duplicates, to be sure I sort by occ(urrences) and I again see that I have two entries with the same ID (primary key).
    I also verified that no ID is added twice (as shown in the code snippet).

    Did I miss something when defining the DataSource?
    Do I have to set some property for ListGrid?

    Anyhow, I'm very confused how it's possible to have two entries with the same primary key.

    Any hints and help is very much appreciated. Thanks in advance.

    #2
    Something is wrong in your code to generate records. You are creating the duplicates.

    Also, if you are going to populate a client-only DataSource, do it via setTestData(), not a series of addData() calls.

    Comment


      #3
      Thanks for the fast reply.
      I think as you can see in the sample code above I do NOT create the duplicates...a for-loop in order to generate the UNIQUE ID's...I don't see how this is a problem with the code, or do you see any?
      Now I use the same code in order to generate the records but use setCacheData() (according to your JavaDoc setTestData() is deprecated) ... and guess what, now I don't have duplicates.
      Anyhow, thanks for pointing me to the right direction.

      Comment


        #4
        Your posted sample code just shows a variable "generatedListGridRecord" and doesn't show how that's generated, so it doesn't give anyone a chance to see, one way or another, whether you have a bug.

        Switching to setCacheData() shouldn't change your duplicates problem either. It still seems as though you had a bug, and happened to correct it when you re-arranged the code.

        Comment


          #5
          Code:
          int count = 0;
          for (Items i : lotsOfItems) {
            count++;
            // create ListGridRecord with id set to count
            ds.addData(generatedListGridRecord);
          }
          // create ListGridRecord with id set to count
          and "count" is incremented, I hoped this should've been clear that the ID is unique .. if not I'm apologizing for not being concrete enough

          anyway, it worked without any re-arranging of the code.

          anyhow, perhaps you can point out in your documentation (https://www.smartclient.com/smartgwt...taSources.html) to use "setTestData" or "setCacheData" instead of adding the records directly to the datasource via "addData"

          thanks again

          Comment


            #6
            Yes, we saw that you put in a comment saying the code was correct. Unfortunately, the actual code was not there to analyze. If you really think your code was correct and that the addData() function somehow scrambles primary keys, you can try putting together a minimal, ready-to-run test case demonstrating this. In the meantime, since hundreds of our automated tests would most likely fail if such a problem really existed, and we have no sample code we can run, we don't plan to investigate further.

            The docs for DataSource.clientOnly tell you to use setCacheData(), and suggest several other ways of populating a clientOnly DataSource (none of which is to use addData() in a loop).

            Comment

            Working...
            X