2017-06-01 71 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();