Announcement

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

    5.1p: RadioGroupItem in SectionStackSection-controls looses it's value after SectionStackSection-title update

    Hi Isomorphic,

    I have a problem in my application (using v10.1p_2017-10-05) where a SectionStackSection controls-RadioGroupItem looses it's value after setting a new title for the section.
    As you can see, with the setTitle() in DataArrivedHandler, the RadioGroupItem looses the value (both entries unselected). Without the setTitle()-call, it does not.

    BuiltInDS.java:
    Code:
    package com.smartgwt.sample.client;
    
    import java.util.LinkedHashMap;
    
    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.DataSource;
    import com.smartgwt.client.types.Alignment;
    import com.smartgwt.client.types.OperatorId;
    import com.smartgwt.client.types.VerticalAlignment;
    import com.smartgwt.client.util.Page;
    import com.smartgwt.client.util.PageKeyHandler;
    import com.smartgwt.client.util.SC;
    import com.smartgwt.client.widgets.Canvas;
    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.RadioGroupItem;
    import com.smartgwt.client.widgets.form.fields.events.ChangedEvent;
    import com.smartgwt.client.widgets.form.fields.events.ChangedHandler;
    import com.smartgwt.client.widgets.grid.ListGrid;
    import com.smartgwt.client.widgets.grid.ListGridField;
    import com.smartgwt.client.widgets.grid.events.DataArrivedEvent;
    import com.smartgwt.client.widgets.grid.events.DataArrivedHandler;
    import com.smartgwt.client.widgets.layout.HLayout;
    import com.smartgwt.client.widgets.layout.SectionStack;
    import com.smartgwt.client.widgets.layout.SectionStackSection;
    import com.smartgwt.client.widgets.layout.VLayout;
    
    public class BuiltInDS extends VLayout implements EntryPoint {
        private IButton recreateBtn;
        private RadioGroupItem ageRGI;
        private ListGrid animalsLG;
        private SectionStackSection sss;
    
        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("RadioGroupItem in SectionStackSection-controls looses it's value after SectionStackSection-title update" + getTitle());
                setShowMinimizeButton(false);
                setIsModal(true);
                setShowModalMask(true);
                centerInPage();
    
                DynamicForm ageForm = new DynamicForm() {
                    {
                        setWidth(530);
                        // Resetting to default. (See DefaultApperanceSetter.setDynamicFormDefaultApperance())
                        setRequiredTitleSuffix(":");
                        ageRGI = new RadioGroupItem() {
                            {
                                setName("AGE");
                                setNumCols(2);
                                setTitle("Age");
                                setColWidths("*", "*");
                                setRequired(true);
                                setVertical(false);
                                LinkedHashMap<Boolean, String> optionMap = new LinkedHashMap<Boolean, String>();
                                optionMap.put(false, "<= 20");
                                optionMap.put(true, ">20");
                                setValueMap(optionMap);
                                setDefaultValue(true);
                                setRedrawOnChange(true);
                                addChangedHandler(new AnimalAgeChangedHandler());
                            }
                        };
                        setFields(ageRGI);
                    }
                };
    
                SectionStack ss = new SectionStack();
                sss = new MySectionStackSection();
                sss.setTitle("Animals");
                animalsLG = new AnimalsLG(true, sss);
                sss.setItems(animalsLG);
                sss.setControls(ageForm);
                ss.setSections(sss);
                addItem(ss);
            }
        }
    
        private class AnimalsLG extends ListGrid {
            public AnimalsLG(boolean older20, final SectionStackSection parentSectionStackSection) {
                super(DataSource.get("animals"));
                setWidth(1000);
                setHeight(500);
                setAutoFetchData(false);
                setAutoFitExpandField("commonName");
                ListGridField lifeSpanLGF = new ListGridField("lifeSpan");
                ListGridField commonNameLGF = new ListGridField("commonName");
                ListGridField statusLGF = new MyLGF("status");
                setFields(commonNameLGF, lifeSpanLGF, statusLGF);
                setSortField("commonName");
    
                addDataArrivedHandler(new DataArrivedHandler() {
                    @Override
                    public void onDataArrived(DataArrivedEvent event) {
                        SC.logInfo("Animals (" + getResultSet().getLength() + ")");
                        parentSectionStackSection.setTitle("Animals (" + getResultSet().getLength() + ")");
                    }
                });
    
                if (older20)
                    fetchData(new AdvancedCriteria(new Criterion("lifeSpan", OperatorId.GREATER_THAN, "20")));
                else
                    fetchData(new AdvancedCriteria(new Criterion("lifeSpan", OperatorId.LESS_OR_EQUAL, "20")));
                ;
            }
        }
    
        private class MySectionStackSection extends SectionStackSection {
            @Override
            public void setControls(Canvas... controls) {
                HLayout hLayout = new HLayout(5);
                hLayout.setAlign(Alignment.RIGHT);
                hLayout.setLayoutRightMargin(10);
                hLayout.setHeight(39);
                for (Canvas s : controls) {
                    VLayout vLayout = new VLayout(0);
                    vLayout.setHeight(39);
                    vLayout.setAlign(VerticalAlignment.CENTER);
                    vLayout.setMembers(s);
                    hLayout.addMember(vLayout);
                }
                super.setControls(hLayout);
            }
        }
    
        private final class AnimalAgeChangedHandler implements ChangedHandler {
            @Override
            public void onChanged(ChangedEvent event) {
                boolean onPicklist = Boolean.valueOf(ageRGI.getValue().toString());
                if (animalsLG != null) {
                    sss.setItems();
                    animalsLG.destroy();
                }
                animalsLG = new AnimalsLG(onPicklist, sss);
                sss.setItems(animalsLG);
                sss.setExpanded(true);
            }
        }
    }
    Best regards
    Blama

    #2
    We've fixed this issue back to SGWT 4.1p/SC 9.1p, and the fixes for SGWT 5.1p/SC 10.1p and newer releases should be in today's nightly builds dated 2017-10-20. (Older branches will be addressed in tomorrow's builds.)

    Comment


      #3
      Hi Isomorphic,

      using v11.1p_2017-10-20 I get this error for the testcase in FF26 Dev Mode:
      Code:
      Error :Cannot change the items property for SectionStackSection isc_BuiltInDS_MySectionStackSection_0 now that it's been added to SectionStack isc_SectionStack_0 and its SectionHeader built
      The error is for this line:
      Code:
          private final class AnimalAgeChangedHandler implements ChangedHandler {
              @Override
              public void onChanged(ChangedEvent event) {
                  boolean onPicklist = Boolean.valueOf(ageRGI.getValue().toString());
                  if (animalsLG != null) {
      [B]                sss.setItems();[/B]
                      animalsLG.destroy();
                  }
                  animalsLG = new AnimalsLG(onPicklist, sss);
                  sss.setItems(animalsLG);
                  sss.setExpanded(true);
              }
          }
      Best regards
      Blama

      Comment


        #4
        Hi Isomorphic,

        also, please see this code (v10.1p_2017-10-05), which shows an related issue in the same area (SectionStackSection editing in DataArrivedHandler).
        The code "parentSectionStackSection.setTitle(parentSectionStackSection.getTitle() + " (" + getResultSet().getLength() + ")");" does show what is meant, but should not work.
        getTitle() should return the current title, so that after filtering, the title should be e.g. "Animals (10) (5)", but it is "Animals (5)".
        It seems that even though the title is correctly set, the variable holding it not changed.

        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.DataSource;
        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.grid.ListGrid;
        import com.smartgwt.client.widgets.grid.ListGridField;
        import com.smartgwt.client.widgets.grid.events.DataArrivedEvent;
        import com.smartgwt.client.widgets.grid.events.DataArrivedHandler;
        import com.smartgwt.client.widgets.layout.SectionStack;
        import com.smartgwt.client.widgets.layout.SectionStackSection;
        import com.smartgwt.client.widgets.layout.VLayout;
        
        public class BuiltInDS extends VLayout implements EntryPoint {
            private IButton recreateBtn;
            private ListGrid animalsLG;
            private SectionStackSection sss;
        
            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("SectionStackSection.getTitle() does not return current title, but initial one" + getTitle());
                    setShowMinimizeButton(false);
                    setIsModal(true);
                    setShowModalMask(true);
                    centerInPage();
        
                    SectionStack ss = new SectionStack();
                    sss = new MySectionStackSection();
                    sss.setTitle("Animals");
                    animalsLG = new AnimalsLG(sss);
                    sss.setItems(animalsLG);
                    ss.setSections(sss);
                    addItem(ss);
                }
            }
        
            private class AnimalsLG extends ListGrid {
                public AnimalsLG(final SectionStackSection parentSectionStackSection) {
                    super(DataSource.get("animals"));
                    setWidth(1000);
                    setHeight(500);
                    setAutoFetchData(false);
                    setAutoFitExpandField("commonName");
                    ListGridField lifeSpanLGF = new ListGridField("lifeSpan");
                    ListGridField commonNameLGF = new ListGridField("commonName");
                    ListGridField statusLGF = new MyLGF("status");
                    setFields(commonNameLGF, lifeSpanLGF, statusLGF);
                    setShowFilterEditor(true);
                    setSortField("commonName");
        
                    addDataArrivedHandler(new DataArrivedHandler() {
                        @Override
                        public void onDataArrived(DataArrivedEvent event) {
                            SC.logInfo("Animals (" + getResultSet().getLength() + ")");
                            parentSectionStackSection.setTitle([B]parentSectionStackSection.getTitle()[/B] + " (" + getResultSet().getLength() + ")");
                        }
                    });
                    fetchData();
                }
            }
        }
        Best regards
        Blama

        Comment


          #5
          Originally posted by Blama View Post
          Hi Isomorphic,

          using v11.1p_2017-10-20 I get this error for the testcase in FF26 Dev Mode:
          Code:
          Error :Cannot change the items property for SectionStackSection isc_BuiltInDS_MySectionStackSection_0 now that it's been added to SectionStack isc_SectionStack_0 and its SectionHeader built
          The error is for this line:
          Code:
          private final class AnimalAgeChangedHandler implements ChangedHandler {
          @Override
          public void onChanged(ChangedEvent event) {
          boolean onPicklist = Boolean.valueOf(ageRGI.getValue().toString());
          if (animalsLG != null) {
          [B] sss.setItems();[/B]
          animalsLG.destroy();
          }
          animalsLG = new AnimalsLG(onPicklist, sss);
          sss.setItems(animalsLG);
          sss.setExpanded(true);
          }
          }
          Best regards
          Blama
          Yes, this is by design. SectionStackSection.items is an [i] field, meaning it can only be set during initialization, and not afterwards, so your approach is incorrect usage. Instead, you need to recreate the SSS if you need to change items, and use the SectionStack APIs to replace the existing SSS.

          This warning, like a few others we issue during SGWT object construction, doesn't abort the control flow, to preserve backcompat - since though not guaranteed or recommended, if it's working in your case we didn't want to break it.

          Comment


            #6
            Hi Isomorphic,

            thanks for the explanation. In my application, I always have 2 VLayouts (for design reasons) in setItems() and the real content is in the 1st VLayout. Therefore this is still working for me without a warning.
            Then the issue from #1 is fixed for me and only the issue from #4 is open.

            Best regards
            Blama

            Comment


              #7
              Your behavior in #4 is because the getter retrieves the property from the SectionStackStack instance, which is a read-only object, but the setter routes to SectionStack.setSectionTitle(), which modifies the SectionHeader.

              We may change how the getter on SectionStackSection operates, but for now, if you want to get the current title, you can get the SectionHeader from the SectionStackSection, and then call getTitle() on it. (That will still work going forward, but we may decide to have the getter on SectionStackSection do that so that section's current property is always returned.)

              We'll update this thread as new information is available.

              Comment

              Working...
              X