Change icon of getWindow().open()?


I’m showing generated PDF files to the user via

getWindow().open(resource, "_blank");

Unfortunately, these windows all have the fav icon from Tomcat. Is there a chance to change that?

Best regards



I guess it depends on from where your PDF is actually loaded - the browser loads the favicon from there. Try checking from which location favicon.ico is loaded (e.g using firebug), and make sure your server/application is returning the icon you want.

At least that’s what I think is going on…

Best Regards,

Hi Marc,

below is the html code of the window containing the pdf file. There is no favicon mentioned.

    <meta name="viewport" content="width=device-width; height=device-height;">
    <title>Report.pdf (application/pdf-Objekt)</title>
  <body marginwidth="0" marginheight="0">
    <embed width="100%" height="100%" name="plugin"
      src="http://localhost:8080/web/APP/5/Report.pdf" type="application/pdf">

I open the window like this:

    final StreamResource resource = new StreamResource(new StreamResource.StreamSource()
      public InputStream getStream()
        return new ByteArrayInputStream(repOut.toByteArray());
    }, "Report.pdf", getApplication());
    getWindow().open(resource, "_blank");

I can’t see a possibility to set the favicon in the StreamResource or elsewhere.

Do you have another idea?



In the meantime I tried to access the newly created window and set the icon manually. Unfortunately, I can’t access this window. I can see it in the debugger in the (not accessible) property named
which is a LinkedList of Window$OpenResource.

So, still no luck…

I create now a new Window for each pdf StreamResource which is put into the window via an Embedded component. Proceeding this way, my pdf window has now the favicon of my application. This is much better then the Tomcat icon… On the other side, this window has much more html code than before.

In another thread I read that I have to create my own ApplicationServlet and override writeAjaxPageHtmlHeader() to change the favicon dynamically. This is where I stuck now: I don’t know how/where to write the different favicon information.

Can someone please put me in the right direction?




I’m going to discuss your first solution first:

The reason you get the Tomcat favicon is because what you’re opening is not actually a Vaadin window - it’s a regular window showing a PDF directly. The HTML code you see is not generated by Vaadin, but by the browser (which browser are you using BTW?) In this case the favicon is not referenced by the HTML, but the browser (some browsers at least) get it from the web sites root,
has more info.
I.e you could try putting your favicon.ico in the website root.

Also note that when opening the window like this, you’ll almost certainly run in to problems with popup blockers; consider using a Link.

As for your second solution, the favicon stuff is written in
and looks like this:

        // Add favicon links
        page.write("<link rel=\"shortcut icon\" type=\"image/\" href=\""
                + themeUri + "/favicon.ico\" />");
        page.write("<link rel=\"icon\" type=\"image/\" href=\""
                + themeUri + "/favicon.ico\" />");

A third option would be to generate the embedding HTML on the fly, not using a Vaadin window (since you don’t actually want the window to be a Vaadin window in your case, just a PDF window).



thank you for your reply. I had a look in the original Vaadin source codes of AbstractApplicationServlet#writeAjaxPageHtmlHeader. I created my own ApplicationServlet and handle the favicon links myself depending on the url and/or title.

I do like the thin html code of the original approach, but I don’t have currently the time to write the whole html code for such windows myself. I can live with the overhead generated by Vaadin for the “normal” windows with embedded pdf files.

Thanks again and have a nice weekend