2

我需要为表格的每一行添加按钮。该表的容器数据源是 JPAContainer。怎么做?我已成功为数据源不是 JPAContainer 的表添加按钮。这就是我所做的:

testable.addContainerProperty("button", Button.class, null);
Button btt = new Button("test");
Item newrow = testable.addItem("first");
newrow.getItemProperty("button").setValue(btt);

但是如果我声明可测试的数据源: testable.setContainerDataSource(jpa_test); 它不起作用。有人能帮助我吗

4

1 回答 1

-1

首先,创建示例类:

public class ExampleBean {
    private Integer id;
    private Button button;

    public ExampleBean() {
        button = new Button("Test") {
            {
                addClickListener(new ClickListener() {
                    @Override
                    public void buttonClick(ClickEvent event) {
                        // code here
                    }
                });
            }
        }
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public Integer getId() {
        return id;
    }

    public void setButton(Button button) {
        this.id = id;
    }

    public Button getButton() {
        return button;
    }

    // ToString, Equals and/or HashCode methods if necessary
}

二、创建容器:

private BeanItemContainer<ExampleBean> exampleBeanItemContainer = new BeanItemContainer<ExampleBean>(ExampleBean.class);

接下来,填充容器(将 bean/beans 添加到容器中)并为容器分配表:

exampleBeanItemContainer.addBean(new ExampleBean() {
    {
        setId(1);
    }
});

table.setContainerDataSource(exampleBeanItemContainer);

最后,设置表头和表头可见性:

table.setVisibleColumns(new Object[] { "id", "button" });
table.setColumnHeaders(new String[] { "ID", "Button" });
于 2014-06-25T11:42:08.257 回答