Adding ClickListener to hyperlinks within a Label

I want to create a label that contains some internal text that may have hyperlinks, so the contents of the label might be:

This is a hyperlink, and this is another one.

How can I add a click listener to the individual hyperlinks within the label?

Thanks,

Ian.

Not very easily. Clicking the links would have to run some JavaScript call, which would have to cause a request through the Vaadin client-side engine. Doing that is a bit tricky.

One way to do something like that is to create a CustomLayout from a String using a stream. This way, you can use regular Button components inside HTML (with Reindeer.BUTTON_LINK style).

To make this properly, you need to create a custom widget that parses the contained text for any links with a specific format (e.g. href=“action:foobar”) and send a server event from those.

Extending the Label component (both Label.java and VLabel.java) is probably the right way to go.

…and this would be a very nice addition to the add-on Directory :wink: