sjivan / gwt-ext

Automatically exported from code.google.com/p/gwt-ext
0 stars 0 forks source link

is not possible selectValue in ComboBox retrieved from dataBase #499

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Create a panel with the combobox: 
   RecordDef groupsRecordDef = new RecordDef(new FieldDef[]
    {   new StringFieldDef("name", "name"), 
        new StringFieldDef("id", "id") 
    });
    JsonReader groupsJsonReader = new JsonReader(groupsRecordDef);
    groupsJsonReader.setRoot("groups");
    groupsStore = new Store(groupsJsonReader);
    groupsComboBox = new ComboBox();
    groupsComboBox.setFieldLabel("Group");
    groupsComboBox.setStore(groupsStore);
    groupsComboBox.setDisplayField("name");
    groupsComboBox.setMode(ComboBox.LOCAL);
    groupsComboBox.setTriggerAction(ComboBox.ALL);
    groupsComboBox.setForceSelection(true);
    groupsComboBox.setValueField("id");
    groupsComboBox.setEditable(false);
    groupsComboBox.setReadOnly(true);
    groupsComboBox.setAllowBlank(false);
    add(groupsComboBox);
....

2. Using a Remote Service (GWT) retrieve the data from Database:
private UserServiceAsync userService = (UserServiceAsync)
GWT.create(UserService.class);
userService.getGroups(new AsyncCallback<String>() {

      public void onSuccess(String jsonData)      {
        // retrieve data. All the groups in the combobox
        groupsStore.loadJsonData(jsonData, false);
        groupsStore.commitChanges();
      }

      public void onFailure(Throwable caught)
      {// 
      }
    });

3. Now the list of "groups" exists in the Combobox. Now i want to select a
element: 

loadButton = new Button("Load Data", new ButtonListenerAdapter()
{
  public void onClick(Button button, EventObject e){
    userService.getUser(userId, new AsyncCallback<String>()
    {
      @Override
      public void onSuccess(String result)
      {

        JSONObject jsonGroup = JSONParser.parse(result).isObject();
        // parse result and obtain a ID. I want to select the 
        // element in the comboBox with this ID.
        ....
        String id = "2";
         groupsComboBox.selectByValue(id,true);
         doLayout();
        }
      }

    });

});

What is the expected output? What do you see instead?

 I expected that the comboBox appear selected with the value.

Please use labels and text to provide additional information.
gwt-ext 2.0.6

Original issue reported on code.google.com by fernando.rosado on 17 Jun 2009 at 5:24

GoogleCodeExporter commented 8 years ago
look at documentation:

http://gwt-ext.com/docs/2.0.4/com/gwtext/client/widgets/form/ComboBox.html#selec
tByValue(java.lang.String,%20boolean)

Select an item in the dropdown list by its data value. This function does NOT 
cause
the select event to fire. The store must be loaded and the list expanded for 
this
function to work, otherwise use setValue. 

Original comment by nietz...@gmail.com on 16 Jul 2009 at 11:06

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
This is now a pretty old Thread, but as I just had to remind myself of how to 
do this and stumbled on this Thread, I thought I'd quickly add a tip:

If you wish to select a value in the combo (which is bound to a Store), you use 
the setValue, passing the value in which relates to the field that was 
specified by using the setValueField method.

Let's say you have a store that has the fields: person_id and name

You will wish to specify that the value display is provided by the 'name' field 
- by calling setDisplayField("name");

You will also need to tell the combo, that the actual value itself is 
represented by the 'person_id' field 
- by calling setValueField("person_id");

Now - to select the person whose person_id is 287, you can call:
- setValue("287");

The value will be selected as you wish, it will be displayed and all is good.

Hope that helps - Happy coding.

Peter Hedderley.

Original comment by peter.he...@googlemail.com on 25 May 2011 at 9:34