Announcement

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

    5.0p Criteria Criterion AdvancedCriteria clientside problems

    Hi Isomorphic,

    please see this BuiltInDS based testcase (v10.0p_2015-11-18).

    BuiltInDS.java:
    Code:
    package com.smartgwt.sample.client;
    
    import com.google.gwt.core.client.EntryPoint;
    import com.smartgwt.client.core.KeyIdentifier;
    import com.smartgwt.client.data.AdvancedCriteria;
    import com.smartgwt.client.data.Criteria;
    import com.smartgwt.client.data.Criterion;
    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.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("Criteria subclasses");
            w.setShowMinimizeButton(false);
            w.setIsModal(true);
            w.setShowModalMask(true);
            w.centerInPage();
    
            IButton b1 = new IButton("Not OK. Criterion destroyed.", new ClickHandler() {
                @Override
                public void onClick(ClickEvent event) {
                    Criterion c = new Criterion("f1", OperatorId.EQUALS, 1000);
                    SC.say(c.asAdvancedCriteria().asString());
                }
            });
            b1.setWidth(300);
    
            IButton b1a = new IButton("Above working.", new ClickHandler() {
                @Override
                public void onClick(ClickEvent event) {
                    Criterion c = new Criterion("f1", OperatorId.EQUALS, 1000);
                    SC.say(new AdvancedCriteria(c).asString());
                }
            });
            b1a.setWidth(300);
    
            IButton b2 = new IButton("OK", new ClickHandler() {
                @Override
                public void onClick(ClickEvent event) {
                    AdvancedCriteria ac = new AdvancedCriteria("f2", OperatorId.EQUALS, 2000);
                    SC.say(ac.asAdvancedCriteria().asString());
                }
            });
    
            IButton b3 = new IButton("OK", new ClickHandler() {
                @Override
                public void onClick(ClickEvent event) {
                    Criterion c = new Criterion("f1", OperatorId.EQUALS, 1000);
                    AdvancedCriteria ac = new AdvancedCriteria("f2", OperatorId.EQUALS, 2000);
                    ac.addCriteria(c);
                    SC.say(ac.asString());
                }
            });
    
            IButton b4 = new IButton("Wrong error message. \"ac\" is not of type Criteria.", new ClickHandler() {
                @Override
                public void onClick(ClickEvent event) {
                    Criteria wrongClass = new Criterion("f1", OperatorId.EQUALS, 1000);
                    final AdvancedCriteria ac = new AdvancedCriteria("f2", OperatorId.EQUALS, 2000);
                    ac.addCriteria(wrongClass);
                    SC.say(ac.asString());
                }
            });
            b4.setWidth(300);
            w.addItem(b1);
            w.addItem(b1a);
            w.addItem(b2);
            w.addItem(b3);
            w.addItem(b4);
            w.show();
        }
    }
    While I think that b1 is just a bug, b4 needs more explanation.
    What is supposed to work here?
    In my real usecase I have a method returning an object that gets added to an AdvancedCriteria. The object added is either Criteria/Criterion/AdvancedCriteria so I thought having a Criteria-signature should work, but it does not.

    Best regards
    Blama

    #2
    The Criteria object represents simple Criteria (field-value pairs without operators).

    A Criterion is meant to be used as part of an AdvancedCriteria and doesn't really have a function on it's own.

    Hopefully this clarifies usage. We do see that the inheritance chain allows you to write code that doesn't match up to the intended usage described in the docs, hence your confusion.

    As far as whatever you're getting from "asString()", please remember that a test case will often be required, but *a description of the problem is always required*. For many different possible reasons, a test case may or may not replicate whatever behavior you see as bad, so we always need to start *first* with a description of what's going wrong.

    Comment


      #3
      Hi Isomorphic,

      sorry for not replying earlier.
      For the 1st button, you see that the criterion is destroyed. The three parts of the criterion (fieldName, operator, value) are interpreted as a criteria each with strange results.
      I'd expect a warning in the DeveloperConsole or automatic correct behavior/result like for the 2nd button.

      For the last button, for which the error is most likely is related to the Java inheritance chain, I'd expect that it works - that AdvancedCriteria.addCriteria(Criteria c) recognizes if the parameter is an instance of Criteria or Criterion and acts accordingly. But at least an error message is displayed.

      IMHO the behavior of the framework in the 2nd is OK (error and the developer can act), even though not nice.
      In the former case the framework should either give an error, too, or return the correct result.

      Best regards
      Blama

      Comment


        #4
        We've made a change to address this issue. Please try the next nightly build, dated January 8.

        Regards
        Isomorphic Software

        Comment


          #5
          Hi Isomorphic,

          this is working for me using v10.1p_2016-01-08/PowerEdition.

          Best regards
          Blama

          Comment

          Working...
          X