Reputation: 15835
I am new to Vaadin. I am using a Vaadin table and getting the table data from a database table. So one of the columns data I want to make it as hyperlink.
I am doing something like this
table.addContainerProperty("First Name", Component.class, null);
table.addContainerProperty("Last Name", String.class, null);
table.addContainerProperty("Year", Integer.class, null);
I saw example where I can mention column type as hyperlink. Assuming if I give column type as hyperlink, how can I add hyperlink properties to the row values.
If those values are static I can do it, but they are coming from database and I just bind them.
Upvotes: 2
Views: 1180
Reputation: 1497
You could add generated column to the table and return a link for each table row.
Example:
Assuming there's a property "LinkUrl" in the table's data source holding link's URL.
table.addGeneratedColumn("WebsiteLink", new ColumnGenerator() {
private static final long serialVersionUID = 1L;
@Override
public Object generateCell(Table source, Object itemId, Object columnId) {
String linkUrl = (String) source.getItem(itemId).getItemProperty("LinkUrl").getValue();
Link websiteLink = new Link(linkUrl, new ExternalResource(linkUrl));
websiteLink.setTargetName("_blank");
return websiteLink;
}
});
Edit: or if you are adding items directly to the table, you could add container property with the type Link
and return a link for each Item
.
Upvotes: 2