Announcement

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

    form.saveData does not appear to call form.rememberValues

    SmartGWT Power 3.0 2011-11-16 (same behavior with a 10/27 build)

    Calls to DynamicForm.saveData complete normally (data is persisted properly), but DynamicForm.valuesHaveChanged is still true afterward. I can work around this by calling rememberValues myself in a callback, but I don't think I should have to? e.g., the following yields

    true
    true
    false

    Code:
    		VLayout layout = new VLayout();
    		final DynamicForm form = new DynamicForm();
    
    		form.setDataSource(DataSource.get(ds.dataSourceId()));
    		Criteria filter = new Criteria(ds.companyIdField(), "501");
    		form.fetchData(filter);
    
    		ToolStrip menu = new ToolStrip();
    		ToolStripButton save = new ToolStripButton();
    		save.setIcon("icons/save.png");
    		save.setTooltip("save");
    		save.addClickHandler(new ClickHandler() {
    			public void onClick(ClickEvent event) {
    				GWT.log(form.valuesHaveChanged().toString());
    				form.saveData(new DSCallback() {
    					public void execute(DSResponse response, Object rawData, DSRequest request) {
    						GWT.log(form.valuesHaveChanged().toString());
    						form.rememberValues();
    						GWT.log(form.valuesHaveChanged().toString());
    					}
    				});
    			}
    		});
    		menu.addButton(save);
    
    		layout.addMember(menu);
    		layout.addMember(form);
    
    		layout.draw();

    #2
    So, a bug then?

    Comment


      #3
      This looks to be a timing thing - the callback fires before the form has been populated with the record-as-saved returned by the server. Try adding a button so you can check valuesHasChanged() after the entire saveData() interaction completes.

      Comment


        #4
        No, my test case is just a goofy way of illustrating the point. Your way is better, but the problem is the same:

        Code:
        	public void onModuleLoad() {
        		
        		DataSource.load("Company", new Function() {
        			public void execute() {
        				loadTestCase(DataSource.get("Company"));
        			}
        		}, false);
        	}
        
        	private void loadTestCase(DataSource ds) {
        		
        		VLayout layout = new VLayout();
        		final DynamicForm form = new DynamicForm();
        
        		form.setDataSource(ds);
        		Criteria filter = new Criteria("COMPANY_UK", "9311235");
        		form.fetchData(filter);
        
        		IButton save = new IButton("Save");
        		save.addClickHandler(new ClickHandler() {
        			public void onClick(ClickEvent event) {
        				form.saveData();
        			}
        		});
        		
        		IButton isDirty = new IButton("Form State");
        		isDirty.addClickHandler(new ClickHandler() {
        			public void onClick(ClickEvent event) {
        				SC.say(form.valuesHaveChanged().toString());
        			}
        		});	
        
        		layout.addMember(form);
        		layout.addMember(save);
        		layout.addMember(isDirty);
        		
        		layout.draw();
        	}

        Comment


          #5
          Still having the same problem with the 3.0 11/27 build. Just looking for confirmation that this isn't some obscure problem on my end...

          Comment


            #6
            We believe this is a framework issue. Someone is scheduled to take a look this week.

            Comment


              #7
              Just checking in to see what was found, if anything...

              Comment


                #8
                Hi Bill,
                We looked into this and it was indeed a bug (or a lacking feature, if you prefer). We really should have 'valuesHaveChanged()' reflect the fact that the form contains live, saved values once a save successfully completes.

                We've made this change in our mainline codebase. However we're currently in the very final stages of putting together 2.5.1 and 3.0 releases and that code is effectively frozen so the change won't make it in there.

                It'll be present in nightly builds going forward after that release and in future releases only.

                So for now you should continue to call 'rememberValues' in your own code. The workaround is straightforward enough we consider this not to be a "release blocker"!

                Regards

                Isomorphic Software

                Comment


                  #9
                  Agreed, not a blocker. Thanks for the update.

                  Comment


                    #10
                    Did this issue ever get resolved in the 3.0 version? I have a Power license, and it appears that valuesHaveChanged() property always returns true even after saveData() is called for a update to a form where form.editRecord(record) is set in the DSCallback for the fetch.

                    I have the following test code:

                    Code:
                    VStack vStack = new VStack();
                    vStack.setLeft(175);
                    vStack.setTop(75);
                    vStack.setWidth("70%");
                    vStack.setMembersMargin(20);
                            
                    DataSource ds = DataSource.get("employees");
                            
                    f1 = new DynamicForm();
                    f1.setDataSource(ds);
                             
                    HiddenItem idItem = new HiddenItem("EmployeeId");
                    idItem.setValue(4);
                            
                    TextItem nameItem = new TextItem("Name");
                    nameItem.setTitle("Name");
                            
                    f1.setFields(idItem, nameItem);
                    f1.setDataSource(ds);
                    f1.fetchData(f1.getValuesAsCriteria(), new DSCallback() {
                    
                    @Override
                    public void execute(DSResponse response, Object rawData,
                    					DSRequest request) {
                    	// TODO Auto-generated method stub
                    	Record[] records = response.getData();
                    	Record record = records[0];
                    	f1.editRecord(record);
                    }
                    });
                            
                    HStack hStack = new HStack();
                    hStack.addMember(f1);
                            
                    IButton saveBtn;
                    saveBtn = new IButton("Save");
                    saveBtn.addClickHandler(new ClickHandler() {
                                public void onClick(ClickEvent event) {
                                	boolean isDirty = f1.valuesHaveChanged();
                                	f1.saveData();
                                	f1.rememberValues();
                                }
                            });
                            
                    vStack.addMember(hStack);
                    vStack.addMember(saveBtn);
                    vStack.draw();
                    The call to valuesHaveChanged() always returns true even if the value in the TextItem never changes.

                    Comment


                      #11
                      No, see above, there's a simple workaround and we'd judged that the full fix is to large to apply to a patch branch (destabilizing).

                      Comment

                      Working...
                      X