我需要为表格的每一行添加按钮。表的容器数据源是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); 它不起作用。请有人帮帮我
答案 0 :(得分:-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" });