Announcement

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

    Datasource

    I have a datasource created with an unique id x

    After my operations , i want it to be destroyed or nullified , and then recreate it with the same ID again.

    what is the best way to do it ?

    My current implementation:

    create a datasource with ID x
    do operations
    destroy datasource()

    try to re create DataSoruce with ID x : this give an error saying
    Cannot change configuration property 'ID' to "X"after the component has been created.

    #2
    I must ask: WHY?

    Comment


      #3
      Currently this will occur if you are attempting to create a DataSource with the same ID as a dataSource which has already been created and has not been destroyed. If you're destroying your old dataSource before creating the new one you should not be seeing this error message.
      Here's a simple test case demonstrating this (If you click 'create' twice you get the error, but if you click create, then destroy, then create you don't).

      Code:
          public void onModuleLoad() {
              
              Button createButton = new Button("Create DS X");
              createButton.addClickHandler(new ClickHandler() {
                  
                  @Override
                  public void onClick(ClickEvent event) {
                      DataSource dsX = createDSX();
                      // ensure it's truly created in JS space - perform a fetch (could just call 'create()' of course)
                      dsX.fetchData();
                      SC.say("X:" + dsX);
                  }
              });
              createButton.draw();
              
              Button destroyButton = new Button("Destroy DX");
              destroyButton.addClickHandler(new ClickHandler() {
                  
                  @Override
                  public void onClick(ClickEvent event) {
                      DataSource dsX = DataSource.get("X");
                      if (dsX == null) {
                          SC.say("No Such DS!");
                      } else {
                          dsX.destroy();
                      }
                  }
              });
      		destroyButton.setTop(50);
      		destroyButton.draw();
      		
      	}
          
          public DataSource createDSX() {
              DataSource ds = new DataSource();
              ds.setClientOnly(true);
              DataSourceField f1 = new DataSourceField("f1", FieldType.TEXT);
              ds.setFields(f1);
              
              ds.setID("X");
              return ds;
          }
      We acknowledge that the error message you're receiving in this case is confusing and we're looking at how to improve the handling of this case, but regardless if you're calling destroy() at the right moment you should not be seeing this message.

      Comment


        #4
        Hey Isomorphic

        Thanks on the pointers , let me get working on this.

        Comment

        Working...
        X