table.setvisiblecolumns problem with composite key

Hi!

i have an entity with composite key. the problem is that i cant show only part of that composite key as a table column.

public static final Object COLUMN_ORDER = new Object
{“entityPK.partOfEntityId”, “name”, “date”};

setVisibleColumns(myContainer.COLUMN_ORDER);

entityPK is composite key for my entity. it consists of two fields (part1, part2). how can i show only one part in the table? if i try “entityPK.part1” it throws:

Caused by: java.lang.IllegalArgumentException: Ids must exist in the Container or as a generated column , missing id: entityPK.part1

any help much appreciated.

Hi,

Depending on your situation, there may be several ways to achieve this, one is to use a ColumnGenerator - it would look something like this (note that I almost always make some errors when I don’t try compiling, so this should be considered pseudo code…):

 table.addGeneratedColumn("entityPK", new ColumnGenerator() {
            public Component generateCell(Table source, Object itemId,
                    Object columnId) {
                Item item = source.getItem(itemId);
                EntitiyPK entityPK = item.getItemProperty("entityPK").getValue();
                return new Label(entityPK.part1); // or whatever is appropriate
            }           
        });

Note that setVisibleColumns() only hides/shows columns already present in the table/datasource based on the ids given - it does no further automagic with that id, so your table should already contain the “entityPK” column, and your column order should look something like this:

public static final Object[] COLUMN_ORDER = new Object[]
{"entityPK", "name", "date"}; 

The column generator above uses the same id as the original column, in order to hide the original column.

Your post includes no information on how you create the Table and/or it’s datasource, so this might not be the best possible solution. Ask or tell more if this does not work for you :slight_smile:

Best Regards,
Marc