Announcement

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

    Short question: Is DynamicForm / ValuesManager saveData() expected to run if valuesHaveChanged() returns false?

    Hi Isomorphic,

    Short question: Is DynamicForm / ValuesManager saveData() expected to run if valuesHaveChanged() returns false?

    I assume this is the case and if I want not to hit the server in that case I'm responsible for this myself using if (valuesHaveChanged())... Could you confirm this?
    I did prepare a testcase for this before figuring out this might be by design, so I'll include it here just in case.

    Code:
    package com.smartgwt.sample.client;
    
    import com.google.gwt.core.client.EntryPoint;
    import com.smartgwt.client.Version;
    import com.smartgwt.client.core.KeyIdentifier;
    import com.smartgwt.client.data.AdvancedCriteria;
    import com.smartgwt.client.data.Criterion;
    import com.smartgwt.client.data.DSCallback;
    import com.smartgwt.client.data.DSRequest;
    import com.smartgwt.client.data.DSResponse;
    import com.smartgwt.client.data.DataSource;
    import com.smartgwt.client.types.OperatorId;
    import com.smartgwt.client.util.Page;
    import com.smartgwt.client.util.PageKeyHandler;
    import com.smartgwt.client.util.SC;
    import com.smartgwt.client.widgets.IButton;
    import com.smartgwt.client.widgets.Window;
    import com.smartgwt.client.widgets.events.ClickEvent;
    import com.smartgwt.client.widgets.events.ClickHandler;
    import com.smartgwt.client.widgets.form.DynamicForm;
    import com.smartgwt.client.widgets.form.ValuesManager;
    import com.smartgwt.client.widgets.form.fields.FormItem;
    import com.smartgwt.client.widgets.layout.HLayout;
    import com.smartgwt.client.widgets.layout.VLayout;
    
    public class BuiltInDS extends VLayout implements EntryPoint {
        private IButton recreateBtn;
    
        public void onModuleLoad() {
            KeyIdentifier debugKey = new KeyIdentifier();
            debugKey.setCtrlKey(true);
            debugKey.setKeyName("D");
    
            Page.registerKey(debugKey, new PageKeyHandler() {
                public void execute(String keyName) {
                    SC.showConsole();
                }
            });
    
            setWidth100();
            setHeight100();
    
            recreateBtn = new IButton("Recreate");
            recreateBtn.addClickHandler(new ClickHandler() {
                @Override
                public void onClick(ClickEvent event) {
                    new MyWindow().show();
                }
            });
            addMember(recreateBtn);
            new MyWindow().show();
            draw();
        }
    
        private class MyWindow extends Window {
            public MyWindow() {
                setWidth("95%");
                setHeight("95%");
                setMembersMargin(0);
                setModalMaskOpacity(70);
                setTitle(" (" + Version.getVersion() + "/" + Version.getSCVersionNumber() + ")");
                setTitle("ValuesManager and DynamicForm saveData() behave differently" + getTitle());
                setShowMinimizeButton(false);
                setIsModal(true);
                setShowModalMask(true);
                centerInPage();
    
                DataSource animalsDS = DataSource.get("animals");
                VLayout mainVLayout = new VLayout(40);
                {
                    final DynamicForm animalsDF1 = new AnimalDF(animalsDS);
                    animalsDF1.setGroupTitle("DynamicForm 1");
                    final DynamicForm animalsDF2 = new AnimalDF(animalsDS);
                    animalsDF2.setGroupTitle("DynamicForm 2");
                    final ValuesManager animalsVM = new ValuesManager();
                    animalsVM.setDataSource(animalsDS);
                    animalsDF1.setValuesManager(animalsVM);
                    animalsDF2.setValuesManager(animalsVM);
    
                    IButton checkButtonDF1 = new IButton("Check DynamicForm 1", new ClickHandler() {
                        @Override
                        public void onClick(ClickEvent event) {
                            SC.say(animalsDF1.valuesHaveChanged().toString());
                        }
                    });
                    checkButtonDF1.setWidth(200);
    
                    IButton checkButtonDF2 = new IButton("Check DynamicForm 2", new ClickHandler() {
                        @Override
                        public void onClick(ClickEvent event) {
                            SC.say(animalsDF2.valuesHaveChanged().toString());
                        }
                    });
                    checkButtonDF2.setWidth(200);
    
                    IButton checkButtonVM = new IButton("Check ValuesManager", new ClickHandler() {
                        @Override
                        public void onClick(ClickEvent event) {
                            SC.say(animalsVM.valuesHaveChanged().toString());
                        }
                    });
                    checkButtonVM.setWidth(200);
    
                    IButton saveButtonVM = new IButton("Save ValuesManager", new ClickHandler() {
                        @Override
                        public void onClick(ClickEvent event) {
                            animalsVM.saveData(new DSCallback() {
                                @Override
                                public void execute(DSResponse dsResponse, Object data, DSRequest dsRequest) {
                                    SC.say("In Callback");
                                }
                            });
                        }
                    });
                    saveButtonVM.setWidth(200);
    
                    VLayout vmButtonsLayout = new VLayout(5);
                    vmButtonsLayout.addMembers(checkButtonDF1, checkButtonDF2, checkButtonVM, saveButtonVM);
    
                    HLayout vmLayout = new HLayout(5);
                    vmLayout.setHeight(400);
                    vmLayout.addMembers(animalsDF1, animalsDF2, vmButtonsLayout);
                    animalsVM.fetchData(new AdvancedCriteria(new Criterion("scientificName", OperatorId.EQUALS, "Allligator mississippiensis")));
                    mainVLayout.addMember(vmLayout);
                }
    
                {
                    final DynamicForm animalsDF3 = new AnimalDF(animalsDS);
                    animalsDF3.setGroupTitle("Single DynamicForm");
    
                    IButton checkButtonDF3 = new IButton("Check single DynamicForm", new ClickHandler() {
                        @Override
                        public void onClick(ClickEvent event) {
                            SC.say(animalsDF3.valuesHaveChanged().toString());
                        }
                    });
                    checkButtonDF3.setWidth(200);
    
                    IButton saveButtonDF3 = new IButton("Save single DynamicForm", new ClickHandler() {
                        @Override
                        public void onClick(ClickEvent event) {
                            animalsDF3.saveData(new DSCallback() {
                                @Override
                                public void execute(DSResponse dsResponse, Object data, DSRequest dsRequest) {
                                    SC.say("In Callback");
                                }
                            });
                        }
                    });
                    saveButtonDF3.setWidth(200);
    
                    HLayout dfLayout = new HLayout(5);
                    dfLayout.setHeight(400);
                    dfLayout.addMembers(animalsDF3, checkButtonDF3, saveButtonDF3);
                    animalsDF3.fetchData(new AdvancedCriteria(new Criterion("scientificName", OperatorId.EQUALS, "Allligator mississippiensis")));
                    mainVLayout.addMember(dfLayout);
                }
                addItem(mainVLayout);
            }
        }
    
        private class AnimalDF extends DynamicForm {
            public AnimalDF(DataSource ds) {
                super();
                setDataSource(ds);
                setAutoFetchData(false);
                setIsGroup(true);
                FormItem scientificName = new FormItem("scientificName");
                FormItem commonNameLGF = new FormItem("commonName");
                FormItem lifeSpanLGF = new FormItem("lifeSpan");
                FormItem statusLGF = new FormItem("status");
                setFields(scientificName, commonNameLGF, lifeSpanLGF, statusLGF);
            }
        }
    }
    Best regards
    Blama

    #2
    If you call saveData() it will save even if there are no changes. The only reason it won't proceed is validation errors (as doc'd).

    This is by design, as the form cannot actually know that it's save will be a no-op (server state could have changed, among other possibilities).

    Comment

    Working...
    X