Announcement

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

    Strange behaviour

    I have a ListGrid which shows a subset of the fields defined in the DataSource, so I use setFields( ... ); for selecting them.

    I used to have the setFields(...) in the constructor of the ListGrid, until I noticed a very strange behaviour.
    When the ListGrid caller calls "listGrid.setCanExpandRecords( true );", the ListGrid shows EVERY FIELD in the DataSource! So the "setFields(...)" is totally ignored.
    If I remove the "listGrid.setCanExpandRecords( true )", the listGrid shows only the fields defined in "setFields(...)", so a correct behaviour.

    The only way I solved this was not calling "setFields(...)" in the constructor, but in a normal method of the ListGrid. Then everything works fine. But this is not normal... could this be a bug?

    Using SmartGWT 3.0p EE

    Edit:
    I think this must be a bug. I isolated the problem:

    Code:
    public void onModuleLoad() {
            SchuelerListGrid lg = new SchuelerListGrid(null,false);
            lg.setWidth( "100%" );
            lg.setHeight( "100%" );
            lg.fetchData();
            //lg.setCanExpandRecords( true );
            lg.draw();
        }
    The constructor:
    Code:
    public SchuelerListGrid( OpenSchuelerManager osm, boolean allowCellBaseStyle )
        {
            super();
            this.osm = osm;
            this.allowCellBaseStyle = allowCellBaseStyle;
            //setLoadingDataMessage( "${loadingImage} " + Zedes2.getConstants().loadingMessage() );
    
            setShowAllRecords( false );
            setAutoFetchData( false );
            setCanEdit( false );
            setShowFilterEditor( true );
            setFilterOnKeypress( true );
            setFetchDelay( 500 );
    
            setSelectionType( SelectionStyle.NONE );
    
            setComponentSort();
    
            setDataSource( DataSource.get( "schueler" ) );
            //setComponentFields();
            
            schuelerIdField = new ListGridField( "f_schueler_id" );
            schuelerIdField.setHidden( true );
            nameField = new ListGridField( "f_name", "name" );
            nameField.setShowHover( false );
            nameField.setWidth( "50%");
            vornameField = new ListGridField( "f_vorname", "vorname" );
            vornameField.setShowHover( false );
            vornameField.setWidth("50%");
            gebDatumField = new ListGridField( "f_geb_datum", "geb" );
            gebDatumField.setShowHover( false );
            gebDatumField.setWidth( 100 );
            ListGridField geschwisterGruppeField = new ListGridField( "geschwister_gruppe" );
            geschwisterGruppeField.setHidden( true );
            setFields( schuelerIdField, nameField, vornameField, gebDatumField, geschwisterGruppeField );
            
        }
    So I set the fields there.

    If I leave the "//lg.setCanExpandRecords( true );" line as a comment, I see everything ok, as you see in my first screenshot. The fields defined are there.
    But if I write "lg.setCanExpandRecords( true );", the fields defined are IGNORED and EVERY SINGLE field of my DataSource is beeing shown (screenshot 2).
    Last edited by edulid; 6 Jul 2012, 07:37.

    #2
    My screenshots
    Attached Files

    Comment


      #3
      This is probably order of operations issue - enabling record expansion causes the ListGrid to have to recalculate it's fields. Try just moving the call before fetchData().

      Comment


        #4
        So enabling record expansion forgets the fields previously set ? Any special reason for that?
        Which other operations forget the fields previously set?

        Comment


          #5
          No, it should not forget the specified fields, and does not in our tests - you haven't really isolated the problem such that we could run the code, you've just isolated it within your larger codebase. Something else is triggering this behavior, but reordering these operations would probably fix it for you.

          Comment


            #6
            That didn't work.
            I isolated the problem further:

            my load module:

            Code:
            import zedes2.client.ui.widgets.listGrids.SchuelerListGrid;
            
            import com.google.gwt.core.client.EntryPoint;
            
            public class Entry implements EntryPoint {
            
                public void onModuleLoad() {
                    SchuelerListGrid lg = new SchuelerListGrid();
                    lg.setWidth( "100%" );
                    lg.setHeight( "100%" );
                    lg.setCanExpandRecords( true );
                    lg.fetchData();
                    lg.draw();
                }
              
            }
            And the listGrid:

            Code:
            package zedes2.client.ui.widgets.listGrids;
            
            import com.smartgwt.client.data.DataSource;
            import com.smartgwt.client.types.SelectionStyle;
            import com.smartgwt.client.widgets.grid.ListGrid;
            import com.smartgwt.client.widgets.grid.ListGridField;
            
            public class SchuelerListGrid
                extends ListGrid
            {
            
                protected ListGridField schuelerIdField;
            
                protected ListGridField nameField;
            
                protected ListGridField vornameField;
            
                protected ListGridField gebDatumField;
            
            
            
                public SchuelerListGrid(  )
                {
                    super();
            
                    setShowAllRecords( false );
                    setAutoFetchData( false );
                    setCanEdit( false );
                    setShowFilterEditor( true );
                    setFilterOnKeypress( true );
                    setFetchDelay( 500 );
            
                    setSelectionType( SelectionStyle.NONE );
            
            
                    setDataSource( DataSource.get( "schueler" ) );
                    
                }
            
            
            
            }
            Even if that would have worked, in my scenarion the situation is more complex and it would be difficult to make sure that the lg.setCanExpandRecords( true ); operation is always called before the fetchData().
            But anyway, that didn't work.

            Comment


              #7
              An unsurprising result given that you have removed the setFields() call altogether :)

              If you need more help with this, try producing minimal, ready-to-run code that reproduces the problem, based on modifications to a Showcase sample.

              Comment


                #8
                You are completely right :-)
                Trying to isolate the problem I deleted "too much" :)

                Here is the correct ListGrid
                Code:
                import com.smartgwt.client.data.DataSource;
                import com.smartgwt.client.types.SelectionStyle;
                import com.smartgwt.client.widgets.grid.ListGrid;
                import com.smartgwt.client.widgets.grid.ListGridField;
                
                public class SchuelerListGrid
                    extends ListGrid
                {
                
                    protected ListGridField schuelerIdField;
                
                    protected ListGridField nameField;
                
                    protected ListGridField vornameField;
                
                    protected ListGridField gebDatumField;
                
                
                
                    public SchuelerListGrid(  )
                    {
                        super();
                
                        setShowAllRecords( false );
                        setAutoFetchData( false );
                        setCanEdit( false );
                        setShowFilterEditor( true );
                        setFilterOnKeypress( true );
                        setFetchDelay( 500 );
                
                        setSelectionType( SelectionStyle.NONE );
                
                
                        setDataSource( DataSource.get( "schueler" ) );
                        
                        schuelerIdField = new ListGridField( "f_schueler_id" );
                        schuelerIdField.setHidden( true );
                        nameField = new ListGridField( "f_name", "name" );
                        nameField.setShowHover( false );
                        nameField.setWidth( "50%");
                        vornameField = new ListGridField( "f_vorname", "vorname" );
                        vornameField.setShowHover( false );
                        vornameField.setWidth("50%");
                        gebDatumField = new ListGridField( "f_geb_datum", "geb" );
                        gebDatumField.setShowHover( false );
                        gebDatumField.setWidth( 100 );
                        ListGridField geschwisterGruppeField = new ListGridField( "geschwister_gruppe" );
                        geschwisterGruppeField.setHidden( true );
                        setFields( schuelerIdField, nameField, vornameField, gebDatumField, geschwisterGruppeField );
                        
                        
                    }
                }
                And, again, the entry point:
                Code:
                import zedes2.client.ui.widgets.listGrids.SchuelerListGrid;
                
                import com.google.gwt.core.client.EntryPoint;
                
                public class Alternate implements EntryPoint {
                
                    public void onModuleLoad() {
                        
                    	
                        SchuelerListGrid lg = new SchuelerListGrid();
                        lg.setWidth( "100%" );
                        lg.setHeight( "100%" );
                        lg.fetchData();
                        lg.setCanExpandRecords( true );
                        lg.draw();
                    }
                  
                }
                And the minimal datasource:
                Code:
                <DataSource ID="schueler" serverType="sql" tableName="t_schueler">
                
                	<fields>
                		<field name="f_schueler_id" type="sequence" primaryKey="true" />
                		<field name="f_name" type="text" required="true" />
                		<field name="f_vorname" type="text" />
                
                		<field name="f_geb_datum" type="date" required="true" />
                
                		<field name="geschwister_gruppe" type="integer" />
                
                	</fields>
                
                </DataSource>
                And you are right, switching the calls solves the problem.
                But as I told you, it would be difficult to make sure that the operations are always in the right operation order.

                And you said:
                "No, it should not forget the specified fields". So this shouldn't be happening, or?
                Last edited by edulid; 6 Jul 2012, 08:35.

                Comment


                  #9
                  As you needed, an example based on your showcase: http://www.smartclient.com/smartgwt/showcase/#grid_databinding_ds_fields

                  I marked the lines I edited.

                  Code:
                  package zedes2.client;
                  
                  import com.smartgwt.client.data.DataSource;  
                  import com.smartgwt.client.data.DataSourceField;  
                  import com.smartgwt.client.types.FieldType;  
                  import com.smartgwt.client.widgets.Canvas;  
                  import com.smartgwt.client.widgets.grid.ListGrid;  
                  import com.smartgwt.client.widgets.grid.ListGridField;
                    
                  import com.google.gwt.core.client.EntryPoint;
                  
                  public class Alternate implements EntryPoint {
                  
                  //    public void onModuleLoad() {
                  //        
                  //    	
                  //        SchuelerListGrid lg = new SchuelerListGrid();
                  //        lg.setWidth( "100%" );
                  //        lg.setHeight( "100%" );
                  //        lg.fetchData();
                  //        lg.setCanExpandRecords( true );
                  //        lg.draw();
                  //    }
                      
                      public void onModuleLoad() {  
                          
                          final ListGrid countryGrid = new ListGrid();          
                          countryGrid.setWidth(500);  
                          countryGrid.setHeight(224);  
                          countryGrid.setShowAllRecords(true);  
                          countryGrid.setDataSource(CountryDS.getInstance()); 
                          //EDIT BEGIN
                          countryGrid.setAutoFetchData(false);  
                          //EDIT END
                          countryGrid.setCanEdit(true);
                          
                          //EDIT BEGIN
                          ListGridField countryNameField = new ListGridField("countryName",  "Country");  
                          ListGridField countryCodeField = new ListGridField("countryCode", "Code");  
                          countryGrid.setFields( countryNameField, countryCodeField );
                          countryGrid.fetchData();
                          countryGrid.setCanExpandRecords( true );
                          // EDIT END
                          countryGrid.draw();   
                      }  
                      
                      private static class CountryDS extends DataSource {  
                          // The DataSource would normally be defined external to any classes that use it.  
                    
                          private static CountryDS instance = null;  
                            
                          public static CountryDS getInstance() {  
                              if (instance == null) {  
                                instance = new CountryDS("countryDS_DS");  
                              }  
                              return instance;  
                          }  
                    
                          public CountryDS(String id) {  
                              setID(id);  
                              setRecordXPath("/List/country");  
                              DataSourceField countryNameField = new DataSourceField("countryName", FieldType.TEXT, "Country");  
                              DataSourceField countryCodeField = new DataSourceField("countryCode", FieldType.TEXT, "Code");  
                              DataSourceField independenceField = new DataSourceField("independence", FieldType.DATE, "Independence");  
                              DataSourceField populationField = new DataSourceField("population", FieldType.INTEGER, "Population");  
                              DataSourceField gdpField = new DataSourceField("gdp", FieldType.FLOAT, "GDP ($B)");  
                    
                              setFields(countryNameField, countryCodeField, independenceField, populationField, gdpField);  
                              //EDIT BEGIN
                              setDataURL("ds/country.data.xml");
                              //EDIT END
                          }  
                    
                      }  
                    
                  }
                  As you see here, I only want two fields to appear:
                  Code:
                  ListGridField countryNameField = new ListGridField("countryName",  "Country");  
                          ListGridField countryCodeField = new ListGridField("countryCode", "Code");  
                          countryGrid.setFields( countryNameField, countryCodeField );
                  But I still see ALL fields from the DataSource:

                  (Attached)


                  Switching the operations solves the problem, but you said this should not be happening. So I still think it's a bug.
                  Attached Files

                  Comment


                    #10
                    Thanks. We'll try to address this before the next release.

                    Comment

                    Working...
                    X