How to get generated property from itemId and columnId ?

getGeneratedProperty(Item itemId, Object columnId)… How its possible with the itemId and columnId to get the generated property.
how to achieve it… Any sample code plz post here.

I guess the issue is that a generated column is often not a value, but a set of icons, or buttons, or something that is not data. If your table has data in a cell, it is better to override the property formatter for the column in question instead of generating a cell. I also find that if for calculated data, if the backing object is a bean, it is better to let the bean do the calculation, and not use a generated column.

Often generated cells are computed with a formula, and just generate a formatted label. There is no property for the generated column. If that is your caseyou will have to create one. So you need to do the same computation as the column generator, and use the computed value to create a new ObjectProperty object. It would have been nice to have ColumnGenerator include a getValue() method and a getProperty() method that wrapped the value in a property. But these are not in the interface. This would have allowed getGeneratedCell to be expressed in terms of a getValue() method without creating the risk of two different calculations.

If you just used the generated column to do formatting, and there is data behind, then you can cheat. See section 5.14.5 of the book – the column generator uses the same 3 informations you have to do its work. If that is your case, you can get the property by asking the container behind the table.

table.getContainerDataSource().getItem(itemId).getProperty(columnId).getValue() should give you the value.

In such a case though, you should change your code to do property formatting instead.

Thank You Jean…

My case is to display the generated table contents in .xls using table export addon. For that I need to implement the ExportableColumnGenerator, where I need getGeneratedProperty() and getType()…

I will try the way you said and will leave a reply.

Hey Syed

I know this topic is 2 years old, but I had the exact same problem as you did. I though I’d share my solution anyway though.

Object value = null; Property p = item.getItemProperty(propertyId); if (p != null) { value = p.getValue(); } else { Table.ColumnGenerator generator = table.getColumnGenerator(propertyId); if (generator != null) { value = generator.generateCell(table, itemId, propertyId); } } Basically, what I do for a property that is generated, I check if there is a generator and convert the value then and there. I do an additional check to see if there is a property for the given property id.
Not the most beautiful solution, but it works quite well.