vaadin 7.75 如何将组合框添加到网格? [英] vaadin 7.75 How to add combobox to a grid?

查看:27
本文介绍了vaadin 7.75 如何将组合框添加到网格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是 Vaadin 7.7,我将表格切换到网格.只有我不能像我想要的那样个性化我的细胞.在这里,我想在 arraylist 的列上添加组合框并检索所选值.

I'm on Vaadin 7.7 and I switch tables to the grid. Only I can not personalize my cells as I would like. Here I would like to add comboboxes on a column from an arraylist and retrieve the chosen value.

这是我的一些代码:

在这里我创建我的 IndexedContainer

Here I create my IndexedContainer

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

在这里我添加我的项目:

Here I add my items:

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

最后,我将对象置于可编辑状态,并使用此功能在备份期间执行操作:

Finally I put my object in editable and I use this function to do actions during the backup:

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 {

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

If you have any ideas or suggestions do not hesitate :)

晚安

推荐答案

你可以这样使用:

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 允许网格渲染组件.

And, in grid declaration, you may use an addon that allows grid to render components.

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

获取comboBox的值:

To obtain the value of the comboBox:

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

这篇关于vaadin 7.75 如何将组合框添加到网格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆