How to show custom favicon in Vaadin UI ?

Add this custom Vaadin servlet to show a different favicon (other than the Vaadin default) in your UI application –


import com.vaadin.server.*;
import com.vaadin.spring.server.SpringVaadinServlet;
import org.springframework.stereotype.Component;
import javax.servlet.ServletException;

@Component("vaadinServlet")
public class CustomServlet extends SpringVaadinServlet {

    @Override
    protected void servletInitialized() throws ServletException {
        super.servletInitialized();

        getService().addSessionInitListener((SessionInitListener) event -> event.getSession().addBootstrapListener(new BootstrapListener() {

            @Override
            public void modifyBootstrapFragment(
                    BootstrapFragmentResponse response) {
                // TODO Auto-generated method stub

            }

            @Override
            public void modifyBootstrapPage(BootstrapPageResponse response) {
                response.getDocument().head().
                        getElementsByAttributeValue("rel", "shortcut icon").attr("href", "./images/favicon.png");
                response.getDocument().head()
                        .getElementsByAttributeValue("rel", "icon")
                        .attr("href", "./images/favicon.png");
            }}
        ));

    }
}

Leave a Reply

Your email address will not be published. Required fields are marked *

*

* Copy This Password *

* Type Or Paste Password Here *

45,334 Spam Comments Blocked so far by Spam Free Wordpress

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>