How would I add a click lisener to a BrowserFrame?

I am using a BrowserFrame to allow users to look at html reports stored in a tree. It’s nice because it’s “autonomous”, letting users drill down into the tree however they see fit.

The problem is that my users want to be able to back up sometimes and drill down somewhere else. So, I provided browser history buttons for them. Keeping the browser history buttons updated is almost impossible. I have a servlet listening, and thanks to the initial url I pass to the BrowserFrame, I can mostly intercept clicks on urls so that I can record the history in the buttons and move on. However, to make a long story short, some (absolute) urls do not match my url pattern for my servlet.

The ideal solution would be to have some sort of click listener that would tell me when a url is clicked in the browser frame. That would solve many of my problems for me. I have been struggling with this issue for months now as I learn Vaadin. Right now the only solution I see is to rewrite absolute urls on-the-fly so that I can capture them in my servlet if users click on them.

The thought of this solution gives me nightmares.

What would it take to have a click listener on a BrowserFrame component?

you can use Jsoup to trick users into thinking they are navigating away to another page.

Instead, what you can do is, take a controller, pass it the initial URL, and then through Jsoup, get the entire html content. Next, what you do is, identify all urls(hyperlinks) → convert them to absolute URLs → encode them → pass the encoded URL as a parameter to your own controller.

For images and stylesheets, you can convert them into absolute url.(why waste your own resources, eh?)

when you get the url as a parameter to your own controller everytime, you can totally control the iframe.

I have tried and tested this. Please don’t hesitate to ask further questions.

I ended up changing the urls, adding a pattern and other pertinent information to it, redirecting it to another servlet in web.xml based on the pattern I added. I had all the information on the users since they were logged in, and redirected the output back to the calling page.

That sounds a lot like what you did, except I didn’t use Jsoup or anything else like that.