Java Vaadin设置组合框填充后的值
我的组合框实例是全局创建的,它会被填充,比如说一个公司列表,而值是一个ID。加载文件后,我想检查组合框中是否有该值,然后以编程方式选择它Java Vaadin设置组合框填充后的值,java,combobox,vaadin,vaadin7,Java,Combobox,Vaadin,Vaadin7,我的组合框实例是全局创建的,它会被填充,比如说一个公司列表,而值是一个ID。加载文件后,我想检查组合框中是否有该值,然后以编程方式选择它 class cComboBoxFun extends UI implements ClickListener { ComboBox cb_company; List<cCustomer> ListCust; //default constructor and server conf not really relevant @Ov
class cComboBoxFun extends UI implements ClickListener
{
ComboBox cb_company;
List<cCustomer> ListCust;
//default constructor and server conf not really relevant
@Override
protected void init(VaadinRequest request)
{
//Lets assume the list has been filled already
cb_company = new ComboBox("Company");
for(cCustomer cust : ListCust)
{
cb_company.addItem(cust.mgetId);
cb_company.setItemcaption(cust.mgetId, cust.mgetName);
}
}
class cCustomer()
{
private String name;
private String Id;
public String GetName()
{
return this.name
}
// Same for id
}
假设您的
组合框使用单选模式,您可以使用
cb_company.select(value)
其中value
指向cCustomer.Id
。因此,代码可能如下所示:
cb_company = new ComboBox("Company");
for(cCustomer cust : ListCust)
{
cb_company.addItem(cust.mgetId);
cb_company.setItemcaption(cust.mgetId, cuts.mgetName);
}
//select the first item from the container
cb_company.select(ListCust.get(0));
谢谢,我正试着用这个名字。。。SMHN不适用于我,例如,即使我将id固定为10
cb_company = new ComboBox("Company");
for(cCustomer cust : ListCust)
{
cb_company.addItem(cust.mgetId);
cb_company.setItemcaption(cust.mgetId, cuts.mgetName);
}
//select the first item from the container
cb_company.select(ListCust.get(0));