Announcement

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

    ComboBoxItem/getSelectRecord SMARTGWT 2.2 Bug

    Hi,
    I found one trouble in new 2.2 SmartGWT version. The problem is: getSelectRecord() always return first selected record. This is testcase (using GwtRpcDataSource as datasource).
    Code:
    package com.mycompany.client;
    
    import com.google.gwt.core.client.EntryPoint;
    import com.smartgwt.client.util.SC;
    import com.smartgwt.client.widgets.form.DynamicForm;
    import com.smartgwt.client.widgets.form.fields.ComboBoxItem;
    import com.smartgwt.client.widgets.form.fields.events.ChangedEvent;
    import com.smartgwt.client.widgets.form.fields.events.ChangedHandler;
    import com.smartgwt.client.widgets.layout.VLayout;
    
    public class TestCase implements EntryPoint {
    
    	public void onModuleLoad() {
            VLayout main = new VLayout();		
    		DynamicForm f = new DynamicForm();
    		
            final ComboBoxItem editor = new ComboBoxItem();
            editor.setAutoFetchData(true);
            editor.setOptionDataSource(new TestDataSource());
            editor.setValueField("name");
            editor.setDisplayField("name"); editor.setCriteriaField("name");
            editor.addChangedHandler(new ChangedHandler() {
    			public void onChanged(ChangedEvent event) {
    			  SC.warn(((ComboBoxItem) event.getItem()).getSelectedRecord().getAttribute("name")); 				
    			};        	
            });
            f.setFields(editor);
            main.addMember(f);
    
            main.setWidth100();
            main.setHeight100();
            main.draw();
    
    	}
    	
    	}
    Thanks.

    #2
    I have found the solution:
    Code:
    ...
            final ComboBoxItem editor = new ComboBoxItem() {
                public native ListGridRecord getSelectedRecord() /*-{
        	    
        	    var self = this.@com.smartgwt.client.core.DataClass::getJsObj()();
        	    var ret = self.pickList.getSelectedRecord();   	    
        	    if(ret == null || ret === undefined) return null;
        	    var retVal = @com.smartgwt.client.core.RefDataClass::getRef(Lcom/google/gwt/core/client/JavaScriptObject;)(ret);
        	    if(retVal == null) {
        	        retVal = @com.smartgwt.client.widgets.grid.ListGridRecord::new(Lcom/google/gwt/core/client/JavaScriptObject;)(ret);
        	    }
        	    return retVal;
        	}-*/; 
    ....

    Comment


      #3
      Thank you very very much for your patch.

      Comment


        #4
        Just as an FYI... I tried this fix in SmartGWT Pro 2.3 and it throws me an "self.pickList is undefined" error.

        Comment


          #5
          We're not aware of any problem with the result of 'getSelectedRecord()' called from the changed handler for a ComboBoxItem in SmartGWT 2.3 (Tested on a recent nightly build).

          The initial test case posted here does not include a dataSource definition but when modified to include a test dataSource (code below) is working correctly.

          Code:
              public void onModuleLoad() {
          
                  // Option dataSource
                  DataSource testDS = new DataSource();
                  DataSourceField f1 = new DataSourceField("f1", FieldType.INTEGER);
                  f1.setPrimaryKey(true);
                  DataSourceField f2 = new DataSourceField("name", FieldType.TEXT);
                  
                  testDS.setClientOnly(true);
                  testDS.setFields(f1,f2);
                  testDS.setTestData(new ListGridRecord[] {
                          new ListGridRecord() {{setAttribute("f1",new Integer(1)); setAttribute("name", "One");}},
                          new ListGridRecord() {{setAttribute("f1",new Integer(2)); setAttribute("name", "Two");}}
                  });
                  
                      VLayout main = new VLayout();       
                      DynamicForm f = new DynamicForm();
                      
                      final ComboBoxItem editor = new ComboBoxItem();
                      editor.setAutoFetchData(true);
                      editor.setOptionDataSource(testDS);//new TestDataSource());
                      editor.setValueField("name");
                      editor.setDisplayField("name"); editor.setCriteriaField("name");
                      editor.addChangedHandler(new ChangedHandler() {
                          public void onChanged(ChangedEvent event) {
                            SC.warn(((ComboBoxItem) event.getItem()).getSelectedRecord().getAttribute("name"));               
                          };          
                      });
                      f.setFields(editor);
                      main.addMember(f);
          
                      main.setWidth100();
                      main.setHeight100();
                      main.draw();
              }
          If you believe there is still a bug here, please post complete code (including your dataSource definition and test data) and steps to reproduce, as well as details of which build (version and date) you're seeing the problem on and we'll take a look.

          Thanks
          Isomorphic Software

          Comment

          Working...
          X