简体   繁体   English

Vaadin向现有表添加新列

[英]Vaadin Add new column to existing table

I'm having some problems to add new column to my table that is generated from one JPAContainer. 我在从一个JPAContainer生成的表中添加新列时遇到一些问题。 The question is... I can add a new column to my existing table if my fields are inserted from JPAContainer? 问题是......如果我的字段是从JPAContainer插入的,我可以在现有表中添加一个新列吗? My code looks like... 我的代码看起来像......

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

The error that I'm having is: Caused by: java.lang.UnsupportedOperationException at com.vaadin.addon.jpacontainer.JPAContainer.addContainerProperty(JPAContainer.java:666) at com.vaadin.ui.AbstractSelect.addContainerProperty(AbstractSelect.java:772) at com.vaadin.ui.Table.addContainerProperty(Table.java:4099) 我遇到的错误是:引起:com.vaadin.addon.jpacontainer.JPAContainer.addContainerProperty(JPAContainer.java:666)的com.vaadin.ui.AbstractSelect.addContainerProperty(AbstractSelect.java)中的java.lang.UnsupportedOperationException :772)at com.vaadin.ui.Table.addContainerProperty(Table.java:4099)

Hope someone can help me. 希望可以有人帮帮我。 Thanks for advice! 谢谢你的建议!

I answer to my own, the better solution that I find to this problem is next... 我回答我自己,我发现这个问题的更好的解决方案是下一个......

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

        }
    });

With this form all correctly works, thanks for reading. 所有这些形式都正常工作,感谢阅读。 Greetings 问候

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM