How to create combobox with hardcode data – vaadin?

Good Day!

How to create combobox with hardcode data – vaadin?

combobox

  • At your java class , add the component for the combobox, the java class called – CountryForm.java.

import com.fndong.vaadin.domain.RefCountry;
import com.vaadin.ui.GridLayout;
import com.vaadin.ui.ComboBox;
import java.util.List;
import java.util.ArrayList;
import com.vaadin.data.util.BeanItemContainer;

public class CountryForm extends GridLayout implements View {

private ComboBox selectCounty;

private List<RefCountry> refcountries = new ArrayList<RefCountry>();

// init content
public void initContent() {

selectCounty = createCountrySelect();
}

// method Create Country select
private ComboBox createCountrySelect() {
refcountries = getRefcountries();
BeanItemContainer<RefCountry> objects = new BeanItemContainer<>(RefCountry.class, refcountries);

ComboBox s = new ComboBox(“Country“, objects);
s.addStyleName(“tiny“);
s.setWidth(“15em“);
s.setItemCaptionPropertyId(“countryname“);
s.setImmediate(true);

return s;
}

// data from countryname using entity RefCountry, hardcode the country name
private List<RefCountry> getRefcountries() {
// List<RefCountry> refcountries = new ArrayList<RefCountry>();
refcountries.add(new RefCountry(new Integer(“1“),”Malaysia“));
refcountries.add(new RefCountry(new Integer(“2“),”Indonesia“));
refcountries.add(new RefCountry(new Integer(“3“),”Singapore“));
refcountries.add(new RefCountry(new Integer(“4“),”Thailand“));
return refcountries;
}

}

  • Entity class – RefCountry.java

public final class RefCountry {
private Integer countryid;
private String countryname;

/**
*
*/
public RefCountry(Integer countryid,String countryname) {
super();
this.countryid = countryid;
this.countryname = countryname;
}

// Getter and setter
}

 Aba Maya , cuba taye (Bidayuh) – Don’t be shy, try it first ( english) 

 

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