Search code examples
javauser-interfacesmartgwt

smartgwt add blank row in ComboBoxItem or allow user to set blank value


I am trying to add blank row with null value in ComboBoxItem of smartgwt which is already bind to data source coming from database.

I have tried changes in service layer, controller layer and database too, but that was not recommended by my senior.

All I need to do changes on UI layer only.


Solution

  • Take a look at the Special Values ComboBox SmartGWT showcase demo. I think it does what you want.

    Here is an extract taken from that demo's code (although I recommend you to look at it and study the code to see what's best in your case):

    LinkedHashMap<String,String> hashMap = new LinkedHashMap<String,String>();  
    hashMap.put("**EmptyValue**", "None");  
    hashMap.put("-1", "Not Applicable");  
    
    ComboBoxItem comboBoxItem = new ComboBoxItem();  
    comboBoxItem.setName("filteredCombo");  
    comboBoxItem.setTitle("Choose an item (ComboBox)");  
    comboBoxItem.setAddUnknownValues(false);  
    comboBoxItem.setOptionDataSource(ItemSupplyXmlDS.getInstance());  
    comboBoxItem.setDisplayField("itemName");  
    comboBoxItem.setValueField("itemID");  
    comboBoxItem.setPickListWidth(300);  
    comboBoxItem.setPickListFields(skuField, itemNameField);  
    comboBoxItem.setSpecialValues(hashMap);  
    comboBoxItem.setSeparateSpecialValues(true);