Announcement

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

    DynamicForm validate and validateData()

    Hi Isomorphic,

    I'm having problems to figure out if I should always get my DSCallback executed for validateData(). This does not happen in my application.
    I prepared a testcase (v10.1p_2016-03-17 BuilInDS based), which showed another anomaly.
    For one of my validateData(), there are actually two requests sent.

    See this testcase:
    employees.ds.xml change/addition:
    Code:
            <field name="Job"             title="Title"           type="text"     length="128"> 
                        <validators>
                            <validator type="isUnique" serverOnly="true" />
                        </validators>
                    </field>
          <operationBindings>
                <operationBinding operationType="fetch" operationId="fetchFewColumns" outputs="EmployeeId, Name, Gender" />
            </operationBindings>
    BuiltInDS.java:
    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.fields.FormItem;
    import com.smartgwt.client.widgets.form.fields.HiddenItem;
    import com.smartgwt.client.widgets.layout.LayoutSpacer;
    import com.smartgwt.client.widgets.layout.VLayout;
    
    public class BuiltInDS implements EntryPoint {
        private VLayout mainLayout;
        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();
                }
            });
    
            mainLayout = new VLayout(20);
            mainLayout.setWidth100();
            mainLayout.setHeight100();
    
            recreateBtn = new IButton("Recreate");
            recreateBtn.addClickHandler(new ClickHandler() {
                @Override
                public void onClick(ClickEvent event) {
                    recreate();
                }
            });
            mainLayout.addMember(recreateBtn);
            recreate();
            mainLayout.draw();
        }
    
        private void recreate() {
            Window w = new Window();
            w.setWidth("95%");
            w.setHeight("95%");
            w.setMembersMargin(0);
            w.setModalMaskOpacity(70);
            w.setTitle(" (" + Version.getVersion() + "/" + Version.getSCVersionNumber() + ")");
            w.setTitle("TITLE" + w.getTitle());
            w.setShowMinimizeButton(false);
            w.setIsModal(true);
            w.setShowModalMask(true);
            w.centerInPage();
    
            {
                final MyDynamicForm df1 = new MyDynamicForm(true, false);
                IButton v1 = new IButton("validate()", new ClickHandler() {
                    @Override
                    public void onClick(ClickEvent event) {
                        df1.validate();
                    }
                });
                IButton vd1 = new IButton("validateData()", new ClickHandler() {
                    @Override
                    public void onClick(ClickEvent event) {
                        df1.validateData(new DSCallback() {
                            @Override
                            public void execute(DSResponse dsResponse, Object data, DSRequest dsRequest) {
                                SC.logWarn("form1.validateData() returned");
                            }
                        });
                    }
                });
                LayoutSpacer ls1 = new LayoutSpacer();
                w.addItem(df1);
                w.addItem(v1);
                w.addItem(vd1);
                w.addItem(ls1);
            }
    
            {
                final MyDynamicForm df2 = new MyDynamicForm(false, false);
                IButton v2 = new IButton("validate()", new ClickHandler() {
                    @Override
                    public void onClick(ClickEvent event) {
                        df2.validate();
                    }
                });
                IButton vd2 = new IButton("validateData()", new ClickHandler() {
                    @Override
                    public void onClick(ClickEvent event) {
                        df2.validateData(new DSCallback() {
                            @Override
                            public void execute(DSResponse dsResponse, Object data, DSRequest dsRequest) {
                                SC.logWarn("form2.validateData() returned");
                            }
                        });
                    }
                });
                LayoutSpacer ls2 = new LayoutSpacer();
                w.addItem(df2);
                w.addItem(v2);
                w.addItem(vd2);
                w.addItem(ls2);
            }
    
            {
                final MyDynamicForm df3 = new MyDynamicForm(false, true);
                IButton v3 = new IButton("validate()", new ClickHandler() {
                    @Override
                    public void onClick(ClickEvent event) {
                        df3.validate();
                    }
                });
                IButton vd3 = new IButton("validateData()", new ClickHandler() {
                    @Override
                    public void onClick(ClickEvent event) {
                        df3.validateData(new DSCallback() {
                            @Override
                            public void execute(DSResponse dsResponse, Object data, DSRequest dsRequest) {
                                SC.logWarn("form3.validateData() returned");
                            }
                        });
                    }
                });
                w.addItem(df3);
                w.addItem(v3);
                w.addItem(vd3);
            }
            w.show();
        }
    
        private class MyDynamicForm extends DynamicForm {
            public MyDynamicForm(boolean useJob, boolean fewColumns) {
                super();
                this.setDataSource(DataSource.get("employees"));
                if (fewColumns)
                    this.setFetchOperation("fetchFewColumns");
                this.setAutoFetchData(false);
                this.setCanEdit(true);
    
                HiddenItem employeeId = new HiddenItem("EmployeeId");
                FormItem name = new FormItem("Name");
                FormItem gender = new FormItem("Gender");
                FormItem job = new FormItem("Job");
                if (useJob)
                    this.setFields(employeeId, name, gender, job);
                else
                    this.setFields(employeeId, name, gender);
                this.fetchData(new AdvancedCriteria(new Criterion(employeeId.getName(), OperatorId.EQUALS, 4)));
            }
        }
    }[B][/B]


    Please click the 1st validateData() to see the double request.
    Am I always guaranteed a CallBack-execution when I use validateData() (this is my main question)?

    Best regards
    Blama

    #2
    We clarified some of the usage of validateData() in your other thread, covering that it's a rarely used API (arguably even superseded entirely by new behaviors of validate()).

    validateData() performs client-side validation first, and returns false if a client-side validator fails. In this case no server request will be issued so your callback won't fire. Currently, the SGWT API for validateData() doesn't actually return a boolean value, so you can't detect this scenario - we're fixing that. We'll also be fixing the issue where two requests can be sent.

    Having said all that - what are you actually trying to accomplish? It's unlikely that validateData() is the right API, as improvements elsewhere in the framework have rendered it mostly inapplicable - we might even deprecate it.

    Comment


      #3
      Hi Isomorphic,

      I just saw that the signature changed to boolean, thanks for that.
      I'm no longer using validateData() and changed the code, so there is no issue anymore for me, here.

      Best regards
      Blama

      Comment

      Working...
      X