Vaadin Cell of column behave as a link

I have a table in Vaadin that display data depending on the data type selected in a Tree. For URL type data it shows a row (two columns) URL and the actual URL in the other but is displayed as plain text. I would like that URL to be clickable and opened in another window.

I tried adding a Link to that case but it displays something like com.vaadin.ui.Link@596bf9 instead of the actual link. Here’s the code I use:

xincoTable.addItem(new Object[]{header, header.equals("URL") ? new Link(value,
                                new ExternalResource(value)) : value}, i++);

value has the actual URL string. I saw the tutorial but it uses generated columns so I’m not sure on how to pull it out. I guess part of the issue is that the behavior is desired for only that cell in that case, it’ll be text in all other cases and of course there are other stuff in that columns in other rows as well.

Also asked
here

Any idea?

Hi Javier,

take a look to the
Table
related pages of vaadin book, more exactly to the point “Components Inside a Table”, there is an example of how to implement the behaviour you want to.

Hope this helps.

Javi

That’s the example I refer to. Sadly it uses generated columns. I got the response in stackoverflow:

I have an IndexedContainer which holds multiple links. That container is passed to a GeneratedPropertyContainer, which generates a property dynamically. The ​GeneratedPropertyContainer is the container for my Grid. When displayed, the links are displayed as .toString() representation of links. Here is my code.

[code]
CssLayout linksLayout = new CssLayout();
Link link0 = new Link(“Click Me”, new ExternalResource(“http://vaadin.com/”));
link0.setTargetName(“_blank”);
Link link1 = new Link(“Google”, new ExternalResource(“http://www.google.com”));
link1.setTargetName(“_blank”);
Link link2 = new Link(“Facebook”, new ExternalResource(“http://www.facebook.com”));
link2.setTargetName(“_blank”);
Link link3 = new Link(“Cricbuzz”, new ExternalResource(“http://www.cricbuzz.com”));
link3.setTargetName(“_target”);

    IndexedContainer links = new IndexedContainer();
    links.addContainerProperty("links", Link.class, null);
    Item newItem1 = links.getItem(links.addItem());
    newItem1.getItemProperty("links").setValue(link0);
    Item newItem2 = links.getItem(links.addItem());
    newItem2.getItemProperty("links").setValue(link1);
    Item newItem3 = links.getItem(links.addItem());
    newItem3.getItemProperty("links").setValue(link2);
    Item newItem4 = links.getItem(links.addItem());
    newItem4.getItemProperty("links").setValue(link3);
    GeneratedPropertyContainer linkContainer = new GeneratedPropertyContainer(links);
    Grid linkGrid = new Grid(linkContainer);
    linkGrid.setEditorEnabled(true);
    linkContainer.addGeneratedProperty("delete", new PropertyValueGenerator<String>() {
        @Override
        public String getValue(Item item, Object itemId, Object propertyId) {
            return "Delete";
        }
        @Override
        public Class<String> getType() {
            return String.class;
        }
    });
    linkGrid.getColumn("delete").setRenderer(new ButtonRenderer(e -> 
        linkGrid.getContainerDataSource().removeItem(e.getItemId()))
    );
    linksLayout.addComponent(linkGrid);
    layout.addComponent(linksLayout);

[/code]Here is the output.

29408.jpg