【问题标题】:Vaadin Add new column to existing tableVaadin 将新列添加到现有表
【发布时间】: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)

希望有人可以帮助我。 感谢您的建议!

【问题讨论】:

    标签: java jpa vaadin


    【解决方案1】:

    我自己回答,我发现这个问题的更好解决方案是下一个......

    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";
    
            }
        });
    

    此表格一切正常,感谢阅读。 问候

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-07-20
      • 1970-01-01
      • 2016-11-13
      • 1970-01-01
      • 2019-04-15
      • 2016-07-04
      • 2017-04-29
      相关资源
      最近更新 更多