cancel
Showing results for 
Search instead for 
Did you mean: 

How to develop a dynamic dropdown for explorer ?

hari
Star Contributor
Star Contributor
Hi All,

I want to develop a dropdown to which I would just pass a hasmap of key value pairs and it displays them.
I was looking at MonthFormPropertyRenderer to see how it was implemented and I can see that the values were picked up from the properties file.

Thanks,
Hari.
2 REPLIES 2

yvoswillens
Champ in-the-making
Champ in-the-making
Hi Hari,

that's plain Vaadin. Please check the Vaadin 6 online docs how to do this.

Regards,

Yvo

car82
Champ in-the-making
Champ in-the-making
Hi, look this solution that i create:

<java> ComboBox comboBox = new ComboBox(getPropertyLabel(formProperty));
     comboBox.setRequired(formProperty.isRequired());
     comboBox.setRequiredError(getMessage(Messages.FORM_FIELD_REQUIRED, getPropertyLabel(formProperty)));
     comboBox.setEnabled(formProperty.isWritable());
    
     Object firstItemId = null;
     Object itemToSelect = null;
    
     RecuperoPF pf = new RecuperoPF(); // this is a class that retrive data from a database
     Map <String,String> values = pf.RecuperoDati();
    
     if (values != null) {
         for (Entry<String, String> pfEntry : values.entrySet()) {
           // Add value and label (if any)
           comboBox.addItem(pfEntry.getKey());
          
           if (firstItemId == null) {
             firstItemId = pfEntry.getKey(); // select first element
           }
          
           String selectedValue = formProperty.getValue();
           if (selectedValue != null && selectedValue.equals(pfEntry.getKey())) {
             itemToSelect = pfEntry.getKey(); // select first element
           }
          
           if (pfEntry.getValue() != null) {
             comboBox.setItemCaption(pfEntry.getKey(), pfEntry.getValue());
           }
         }
       }
      
       // Select value or first element
       if (itemToSelect != null) {
         comboBox.select(itemToSelect);
        
       } else if (firstItemId != null) {
         comboBox.select(firstItemId);
       }
      
       return comboBox;
</java>