Setting the Vaadin Bean Property to Convert a Table Cell

We have a BeanItemContainer, which we show as a Vaadin table that works very well. The only problem is that one of the properties of the bean is the url, and we want it to be a link.

Adding "a href = ..." to the url in the setURL () function works, but

  • it will not hit me like very elegant code.
  • other callers now have to remove tags from it after using the get method.

Adding a click listener to the table also works, but

  • it can open a window instead of a bookmark
  • this can be prevented by a popup blocker

Is there a way to control the process of Vaadin converting the values ​​of the bean properties to table cells?

+4
source share
1 answer

Use a column generator in the table and create a Link component, for example

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, eg http://stackoverflow.com String urlDescription = columnValue; // Description is the same as the return new Link(urlDescription, new ExternalResource(urlValue)); } }) 

See javadoc for more details.

+6
source

Source: https://habr.com/ru/post/1403853/


All Articles