2014-10-01 53 views
0

我使用Vaadin ListSelect来显示选项。我有一个模板的标题作为显示名称,但我想从templateContainer中添加一个属性(id)来显示。我该怎么做?如何使用两个属性在Vaadin ListSelect中显示?

ListSelect select = new ListSelect("Templates", templatesContainer); 
select.setItemCaptionPropertyId("title"); 

回答

3

例如:

ListSelect select = new ListSelect("Templates", templatesContainer) { 
    @Override 
    public String getItemCaption(Object itemId) { 
     MyTemplate t = (MyTemplate) itemId; 
     return t.getTitle() + "-" + t.getId(); 
    } 
}; 

或者,如果你使用的容器,你可以直接使用它:

ListSelect select = new ListSelect("Templates", templatesContainer) { 
    @Override 
    public String getItemCaption(Object itemId) { 
     Container c = getContainerDataSource(); 
     String title = (String) c.getContainerProperty(itemId, "title").getValue(); 
     Integer id = (Integer) c.getContainerProperty(itemId, "id").getValue(); 
     return title + "-" + id; 
    } 
};