Embed link in text

Hi folks,

I can’t seem to figure out how to implement this simple requirement w/ Vaadin. I have need to have a single paragraph with links embedded in it. So the html equivalent would look something like this

Hello, my name is John Doe and I was born on Earth. My favorite colors are blue and white.

I can’t use Label w/ the XHTML or XML content type because I need to use clicklisteners for the links.

I would appreciate any inputs.

Thanks!

duy

Add an URIFragmentUtility to your window. Then use a Label in XHTML mode. In your label’s text, use the normal html links with #xxx like urls, for example:

new Label ( "Hello, my name is <a href=\"#name\">John Doe</a> and I was born on <a href=\"#earth\">Earth</a>. My favorite colors are <a href=\"#blue\">blue</a> and <a href=\"#white\">white</a>" );

Once clicked, URIFragmentUtility will fire an uri changed event you may catch by attaching your event listener. There you may capture the new uri fragment (actually, that name you’ve used in your links above) and act accordingly.

Hi Dmitri,

Thanks for the suggestion. I’ve gotten it almost working. The only problem comes when the user clicks the link a second time. How do I “clear” the URIFragmentUtility so that the user can click it multiple times.

Thank you,

duy

Maybe setURIFragment to empty string or another “dummy” value will work ?

Thanks again Dmitri for your thoughts.

I couldn’t find a setURIFragment method anywhere in the Vaadin API (I’m using 6.2). However, I did find a setFragment in the UriFragmentUtility class. Here’s my code:

if (((UriFragmentUtility) fragmentChangedEvent.getSource()).getFragment().equals(“createAccount”)) {
application.updateContentPanel(new RegisterNewAccountPanel(application));
uriFragUtil.setFragment(“temp”);
}

The setFragment works as expected, and the fragment was indeed changed to “temp”. However, because the “createAccount” is in the URL, everytime the ((UriFragmentUtility) fragmentChangedEvent.getSource()).getFragment() gets executed when the page is refreshed, the fragement is always “createAccount”. This effectively means that the if statement will always be true after the first time the link is pressed. It seems the only workaround I can find is to have a counter that counts everytime this value is clicked. This seems rather painful and would introduce another group of problems.

Thank you,

duy