Announcement

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

    SelectItem DataSource refresh problem

    Hello,

    So I have a SelectItem with a binded datasource, with the id as the valuefield and name as the displayfield. I then want to change the name of the currently selected record. I basically create a new datasource with the necessary changes, use clearValue() and set the new datasource, along with setValue(id_of_changed_record). The dropdown is populated alright, with the new name, but whenever I click on the newname in the dropdown, the displayed name would be the old one. A refresh solves this problem, but I would rather have it work automatically ofc. Any suggestions?

    Thanks.

    #2
    Sorry to bump, but no workaround found yet.

    Sample code to illustrate the problem:

    Code:
     final DynamicForm form = new DynamicForm();
            final SelectItem items = new SelectItem();
            MyDS datasource = new MyDS();
            datasource.addData(new MyRecord("1", "mouse"));
            datasource.addData(new MyRecord("2", "cat"));
            datasource.addData(new MyRecord("3", "dog"));
            items.setOptionDataSource(datasource);
            items.setValueField("id");
            items.setDisplayField("name");
            items.setValue("1");
    
            ButtonItem button = new ButtonItem("Change item name");
            button.addClickHandler(new com.smartgwt.client.widgets.form.fields.events.ClickHandler() {
                @Override
                public void onClick(com.smartgwt.client.widgets.form.fields.events.ClickEvent event) {
                    MyDS datasource = new MyDS();
                    datasource.addData(new MyRecord("1", "mouse"));
                    datasource.addData(new MyRecord("2", "cat"));
                    datasource.addData(new MyRecord("3", "YODAWG"));
                    items.clearValue();
                    items.setOptionDataSource(datasource);
                    items.setValue("3");
                }
            });
    
    ----
       class MyDS extends DataSource {
            public MyDS() {
                DataSourceTextField idField = new DataSourceTextField("id", "id");
                idField.setPrimaryKey(true);
                DataSourceTextField nameField = new DataSourceTextField("name", "name");
                setFields(idField, nameField);
                setClientOnly(true);
            }
        }
    
        class MyRecord extends Record {
            public MyRecord(String id, String name) {
                setAttribute("id", id);
                setAttribute("name", name);
            }
        }
    Tried calling items.redraw(), form.redraw() with no change in the result. The dropdown is updated and displays "YODAWG" but the name of the selected record continues to be "dog". Any better solution besides removing the formitems and adding a new selectitem which I'm not so sure would work either?

    Thanks.

    Also, SGWT 3.0, Firefox 22.0
    Last edited by fancyusername; 31 Jul 2013, 07:07.

    Comment

    Working...
    X