Reputation: 12207
We have a BeanItemContainer we display as a Vaadin table which works very well. The only problem is that one of the bean properties is an URL and we want it to be a link.
Adding "a href=..." to the url in the setURL()-function works but
Adding a click listener to the table works as well but
Is there a way to control the process Vaadin transforms bean propery values to table cells?
Upvotes: 4
Views: 2306
Reputation: 3155
Use a ColumnGenerator on the table, and generate a Link component, e.g.
table.addGeneratedColumn("link", new Table.ColumnGenerator() {
@Override
public Object generateCell(Table source, Object itemId, Object columnId) {
Item item = source.getItem(itemId);
String columnValue = String.valueOf(item.getItemProperty(columnId).getValue());
String urlValue = columnValue; // Assume columnValue contains full url including protocol, e.g. http://stackoverflow.com
String urlDescription = columnValue; // Description is the same as the
return new Link(urlDescription, new ExternalResource(urlValue));
}
})
See documentation and javadoc for more details
Upvotes: 6