Add new column to existing table

Hi everyone!

I’m having some problems to add new column to my table that is generated from one JPAContainer.
The question is… I can add a new column to my existing table if my fields are inserted from 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)

Hope someone can help me.
Thanks for advice!

Hi, you’ll probably want to use a generated column:

table_1.addGeneratedColumn("admin_vis", new ColumnGenerator() {
    @Override
    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";
    }
});

Then, no matter how the row content of the container changes, the value is computed on the fly for all the rows. The returned Object can be either a string or a Vaadin component.

When I posted my answer I arrived to the same conclusion as you but your solution is so much better.
So thank you so much Johannes this is exactly that I need.
Greetings.