Adding CellRenderer for Table?

As a user coming from Swing components, are there any plans of adding a CellRenderer to the Table component?

I have just started to use Vaadin, and I prefer a MVC-architecture where I fill up the Container in a Controller and pass it to the View which handles the layout details. I’ve created a view which displays a text in two different ways, short texts are displayed in a Label and longer texts are displayed in a PopupView. As I understood it I have to create the Label or PopupView and add them to the Container, but that makes me mix up view-code and control-code… Are there any other ways of mimic a CellRenderer and separate things a bit more?


I believe you can achieve something similar to the CellRenderer pattern with a ColumnGenerator.

I’ve been using something in the lines of:

myTable.addGeneratedColumn("Col Caption", new Table.ColumnGenerator() {
    public Component generateCell(Table table, Object itemId, Object columnId) {
        BeanItem<MyBean> item = myContainer.getItem(itemId);
        MyBean bean = item.getBean();
        return new ViewForMyBean(bean);

Hope it helps.


Thanks! Just tried it and it seems like a good-enough solution!

Is there any way to register a ColumnGenerator that can handle a specific Type, for example how to format a Timestamp? Would be a nice extension to the Table.addGeneratedColumn(…)!


I guess you can create a generic generator that inspects the class and returns the proper renderer or just let the super do its thing…

Picking up my last example:

MyBean bean = item.getBean();
Property prop = item.getItemProperty(columnId);

Then you can inspect that property class using prop.getType() or even:

if(prop.getValue() instanceof Date) {
   (return/set formatted date)
} else if(prop.getValue() instanceof Number) {
   (return/set formatted number)
} else ...

You can see how it goes from here…


That looks like a nice idea. Question is: How do I register/enable this generic generator?