2017-06-01 82 views
1

我在Vaadin 7.7上,并将表切换到网格。只有我不能个性化我的细胞,因为我想。在这里,我想在arraylist的列中添加组合框并检索选定的值。vaadin 7.75如何将组合框添加到网格?

下面是我的一些代码:

这里创建我IndexedContainer

IndexedContainer indexedContainer = new IndexedContainer(); 
    indexedContainer.addContainerProperty("Type de véhicule",String.class,""); 

这里添加我的项目:

indexedContainer.addItem(listValue); 
    indexedContainer.getContainerProperty(listValue, 
      key.get(0)).setValue(
      String.valueOf(listValue.get(0))); 

最后,我把我的对象编辑和我用这个功能在备份过程中执行操作:

grid.getEditorFieldGroup().addCommitHandler(new FieldGroup.CommitHandler() { 
    @Override 
    public void preCommit(FieldGroup.CommitEvent commitEvent) throws FieldGroup.CommitException { 

    } 
    @Override 
    public void postCommit(FieldGroup.CommitEvent commitEvent) throws FieldGroup.CommitException { 

如果您有任何意见或建议,请不要犹豫:)

晚安

回答

-1

试试这个:

grid.getColumn("state").setEditorField(getComboState()); 

其中getComboState是:

private Field<?> getComboState() { 
    ComboBox comboBox = new ComboBox(); 
    comboBox.addItem("approve"); 
    comboBox.addItem("no-approve"); 
    comboBox.setImmediate(true); 
    comboBox.setNullSelectionAllowed(false); 
    return comboBox; 
} 
0

你可以使用的东西像这样:

List<String> values = obtainValues(); 
IndexedContainer container = new IndexedContainer(); 
//Add other properties... 
container.addContainerProperty("comboBox", ComboBox.class, null); 
//Do more stuff 
ComboBox cb = new ComboBox(); 
cb.addItems(values); 
item.getItemProperty("comboBox").setValue(cb); 

而且,在网格声明中,您可以使用允许网格呈现组件的addon

Grid grid = new Grid(); 
//Even more stuff 
grid.setContainerDataSource(container); 
grid.getColumn("comboBox").setRenderer(new ComponentRenderer()); 

为了获得ComboBox的值:

Item item = container.getItem(itemId); 
ComboBox cb = item.getItemProperty("comboBox").getValue(); 
String value = (String) cb.getValue();