У меня возникли проблемы с добавлением нового столбца в мою таблицу, который создается из одного JPAC-контейнера. Вопрос в том... Я могу добавить новый столбец в существующую таблицу, если мои поля вставлены из 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) at com.vaadin.ui.Table.addContainerProperty(Table.java:4099)
Надеюсь, кто-нибудь может мне помочь. Спасибо за совет!
Я отвечаю на свое собственное, лучшее решение, которое я нахожу для этой проблемы, следующее...
table_1.addGeneratedColumn("mycolumn", new ColumnGenerator() {
public Object generateCell(Table source, Object itemId, Object columnId) {
Item item = source.getItem(itemId);
String admin = (String) item.getItemProperty("admin").getValue();
return admin.equals("Y") ? "true" : "false";
}
});
С этой формой все правильно работает, спасибо за чтение. Приветствую