Announcement

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

    ComboBoxItem.getSelectedRecord() returns the wrong record.

    SmartClient Version: v10.0p_2015-09-24/Pro Deployment (built 2015-09-24)

    I just found a strange bug where my ComboBoxItem returns the wrong record with getSelectedRecord().

    I happens if the displayValue is the same for some of the records in the picklist.

    I have attached a test-case below that illustrates the problem. The comboboxitem has it's value set to 3 when data arrives from the datasource, but if you press the button to read the value of the selected record, it returns 1.

    My real comboboxitem is databound to a datasource with user submittet items so it is very likely that more than one item will have the same display value in my case.


    TEST CASE:
    Code:
    final VLayout mainLayout = new VLayout();
    
    final ComboBoxItem item = new ComboBoxItem();
    item.setOptionDataSource(TestDS.getInstance());
    item.setDisplayField("name");
    item.setValueField("id");
    item.setAutoFetchData(true);
    item.addDataArrivedHandler(new DataArrivedHandler() {
        
        @Override
        public void onDataArrived(DataArrivedEvent event) {
            item.setValue(3);
        }
    });
    Button b2 = new Button("Read Value");
    b2.addClickHandler(new ClickHandler() {
        
        @Override
        public void onClick(ClickEvent event) {
            SC.say("value is: " + item.getSelectedRecord().getAttributeAsInt("id"));
        }
    });
    mainLayout.addMember(b2);
    
    DynamicForm form = new DynamicForm();
    form.setItems(item);
    
    mainLayout.addMember(form);
    mainLayout.draw();
    TestDS:
    Code:
    public class TestDS extends DataSource {  
          
        private static TestDS instance = null;  
      
        public static TestDS getInstance() {  
            if (instance == null) {  
                instance = new TestDS("testDS");  
            }  
            return instance;  
        }  
      
        public TestDS(String id) {  
      
            setID(id);  
            setRecordXPath("/List/testItem");  
            DataSourceIntegerField valueField = new DataSourceIntegerField("id");
            valueField.setPrimaryKey(true);
      
            DataSourceTextField displayField = new DataSourceTextField("name");  
            setFields(valueField, displayField);  
      
            setDataURL("ds/test.data.xml");
            setClientOnly(true);          
        }  
    }
    test.data.xml
    Code:
    <List>  
        <testItem>  
            <id>1</id>  
            <name>Test</name>  
        </testItem>
        <testItem>  
            <id>2</id>  
            <name>Test</name>  
        </testItem>
        <testItem>  
            <id>3</id>  
            <name>Test</name>  
        </testItem>
        <testItem>  
            <id>4</id>  
            <name>Test</name>  
        </testItem>
    </List>

    #2
    Hi Niels_EMP,

    perhaps this is fixed for today's build - see this thread.

    Best regards
    Blama

    Comment


      #3
      Thank you, it seems to be fixed with the latest build.

      Comment

      Working...
      X