setVisibleColumns with untypical situation

My class:

[code]
public class A
{
private String type;

private B b;


}

public class B
{
private int f;

private int p;


}
[/code]When I create table:

[code]
Class aC= A.class;
Class bC= B.class;

    String tp = aC.getDeclaredField(TYPE).getName();  //TYPE == "type"
    String pp = bC.getDeclaredField(FC).getName();    //FC == f
    
    yable.setVisibleColumns(new Object { tp, pp });

[/code]I have an error:

com.vaadin.server.ServiceException: java.lang.IllegalArgumentException: Ids must exist in the Container or as a generated column, missing id: f

Could you have any idea how to omit this problem ?

Hello Areq,

Could you provide a bit more details on how you create the table and the possible container used as a datasource?

  • Matti

Hi,

creating of table

private BeanItemContainer<A> generateDataFromDB() {
       
        elements = new BeanItemContainer<A>(A.class);
      
        
        for ( ... ) {
                  
            elementsDataModel.add(new A(...)));  
        }

        ....

        elements.addAll(elementsDataModel);
        
        return elements;
    }

Thank you for the additional details. When using nested beans in your container, the fields of the nested bean (B) in your case, must be explicitly added as nested properties. Have a look at the
AbstractBeanContainer
api for the methods
addNestedContainerProperty
and
addNestedContainerBean
. After adding the nested property, you can use it in the setVisibleColumns method call. In your case the id for the nested property would be b.f

So the solution would be something along the lines:

elements.addNestedContainerProperty("b.f") 
.....
projectBaselineComplianceTable.setVisibleColumns(new Object { tp, "b.f" });

Best regards,
Matti

Just like the exception tells you. Your BeanItemContainer is a bean item container of A.class. You want to access the property “f” which is not existing in A. If you want to access nested properties, look here
http://magi.virtuallypreinstalled.com/book-examples/book/#datamodel.container.beanitemcontainer.nestedbean

edit: too late, Matti was faster :slight_smile:

Ok, thank you, it works.

But, exist any possibility to implementing it in more elegant way… (After refactoring in classes: A or B, I will must modify generation of table)

Exist any similat function like addNestedContainerProperty for HierarchicalContainer ?

How resolve this problem (nested bean in global bean) for HierarchicalCOntainer ?