How to set the default value into combobox – Vaadin

How to set default value into combobox :

Here is my source codes, i would like make the values that passing from method getGender():

// generate Genders into combobox value
Collection<GenderTable> gendertable= getRecordGenders();
Container container= new ListContainer<RefGenders>(GenderTable.class, genderTable);
combobox_gender.setContainerDataSource(container);
combobox_gender.setItemCaptionPropertyId("nameGender");

noid_textfield.addValueChangeListener(new ValueChangeListener() {
@Override
public void valueChange(ValueChangeEvent event) {
String gender = getGenders(); // returning gender code , F - Female or M - Male
String genderName = "";

if("F".equalsIgnoreCase(gender)){
genderName ="Female";
}else{
genderName ="Male";
}

GenderTable genderTable = new RefGenders(gender, genderName);
PropertysetItem item = new ProppertysetItme();
FieldGroup binder = new FieldGroup(item);
binder(combobox_gender , "GenderTable");
}
});

The result at display page , the Combobox Gender – “combobox_gender” are gray. and its not bind property. any solution that can fix this.

whycombogray

Solution 1 :

1.using gender_combo.setValue(gender_combo.getItemIds().iterator().next()); – to make a default value for ComboBox .

 

Solution 2 :

2. using below code by iterate the combobox value.

@Override
public void valueChange(ValueChangeEvent event) {
 @SuppressWarnings("unchecked")
 Iterator<GenderTable> iterator = (Iterator<GenderTable>) 
 combobox_gender.getItemIds().iterator();
              
              while(iterator.hasNext()) {
                     GenderTable obj = iterator.next();
// getGender - get return value , F - Female , M - Male
                     if(obj.getcodeGender().equals(getGender().trim())){
                         gender_combo.setValue(obj);
                         break;
                     }
                     }
});

SELAMAT MENCUBA! / ABA MAYA WANG ADEP IRA CUBA!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s