Search code examples
smartgwt

smartGWT: how to add items in selectOtherItem


I have create a selectOtherItem in my SmartGWT .

i have just shifted from GWT where we simply do

             listBox.addItem("some Item");

and to put the values coming from a loop and also to save the id against every item (for values coming from db)

             for(int i =0;i <list.size; i++){
          listBox.addItem(list.getName(i), list.getId(i));
               }

but i'm not able to do these stuff in smartGWT . Now i am using selectOtherItem . If you can please guide how i can do the same thing in smartGWT, which i have show above.

thanks


Solution

  • SmartGWT also has the same functionality. You can directly add the Strings to a ComboBoxItem or SelectItem as mentioned below:

    comboboxItem.setValueMap("s", "a", "d");
    

    OR you can also prepare a LinkedHashMap, to specify key-value pair as mentioned below:

    LinkedHashMap<String, String> map = new LinkedHashMap<String, String>();
    for (Obj obj : objList) {
        map.put(String.valueOf(obj.getId()), obj.getName());
    }
    comboboxItem.setValueMap(map);
    

    Besides, you can also fill up a ComboBoxItem or SelectItem using a DataSource.

    For further details, refer this link.