Hi guys,
I’ve experimented 2 ways to customize the output of a table:
- Table.formatPropertyValue, to customize the String.
- ColumnGenerator, to add columns with customized widget.
The tutorial shows an example of the ColumnGenerator for e-mail addresses links:
http://vaadin.com/tutorial/-/page/tuning.html#tuning.addresses
It’s crystal clear to me.
In the tutorial, they retrieve the Person bean to get the mail (p.getEmail()):
// customize email column to have mailto: links using column generator
addGeneratedColumn("email", new ColumnGenerator() {
public Component generateCell(Table source, Object itemId,
Object columnId) {
Person p = (Person) itemId;
Link l = new Link();
l.setResource(new ExternalResource("mailto:" + p.getEmail()));
l.setCaption(p.getEmail());
return l;
}
});
What if the column you wanna decorate is already defined as a column of the table.
Here is an example, where the bean is not in the data source (contrary to the tutorial).
table.addContainerProperty("FirstName", String.class, null);
table.addContainerProperty("e-mail", Date.class, null);
for (Person p : PersonList) {
Object[] rowValues = new Object[]
{
p.getFirstName(),
p.getEmail()
};
table.addItem(rowValues, p.getId()); // getId returns the DB primary key (a Long).
}
In this example, we would like to override a method similar to Table.formatPropertyValue, but to customize the Component (not only the String), so we can return a Link for the “e-mail” column.
We could not create a ColumnGenerator for the “e-mail” column, because the column name already exists (and it better exist, else, we don’t have access to the e-mail data from the table).
The different in the tutorial is that the ColumnGeneator has access to the bean (p.getEmail()) which is stored in the Table.
In my example, the bean is not stored in the table.
Question: is there a way to make the e-mail appear as a link in my example (where the bean is not stored in the table → hard to get in the ColumnGenetor class) ?
Hope this is clear.
Thank you.
John.