【发布时间】:2014-10-18 15:34:05
【问题描述】:
我在将新列添加到从一个 JPAContainer 生成的表中时遇到了一些问题。 问题是......如果我的字段是从 JPAContainer 插入的,我可以在现有表中添加一个新列吗? 我的代码看起来像...
persons = JPAContainerFactory.make(Users.class, PERSISTENCE_UNIT);
persons.sort(new String[]{"niu"}, new boolean[]{true});
table_1.setWidth("100%");
table_1.setSelectable(true); // Hacemos que se puedan seleccionar las filas del Grid.
table_1.setMultiSelect(false);// Selección de múltiples filas del Grid.
table_1.setContainerDataSource(persons);
table_1.addContainerProperty("admin_vis", String.class, null);
for (Iterator i = table_1.getItemIds().iterator(); i.hasNext();) {
Object itemIdentifier = i.next();
Item item = table_1.getItem(itemIdentifier);
String admin = (String) item.getItemProperty("admin").getValue();
Item item1 = ((Container) table_1.getContainerProperty(String.class, "admin_vis")).addItem("row"+i);
if(admin.equals("Y")) {
Property property = item1.getItemProperty("admin_vis");
property.setValue("true");
} else {
Property property = item1.getItemProperty("admin_vis");
property.setValue("false");
}
}
table_1.setVisibleColumns(new Object[] { "niu", "nom", "mail", "admin_vis" });
table_1.setColumnHeaders(new String[] { "Niu", "Nom", "Mail", "Admin", })
table_1.setPageLength(15);
table_1.setImmediate(true);
我遇到的错误是: 引起:java.lang.UnsupportedOperationException 在 com.vaadin.addon.jpacontainer.JPAContainer.addContainerProperty(JPAContainer.java:666) 在 com.vaadin.ui.AbstractSelect.addContainerProperty(AbstractSelect.java:772) 在 com.vaadin.ui.Table.addContainerProperty(Table.java:4099)
希望有人可以帮助我。 感谢您的建议!
【问题讨论】: