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 –

[java]

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”);
}}
));

}
}

[/java]

Sreekumar Kj
Sreekumar (KJ) has been a hobby programmer from school days. Codemarvels is his personal blog from the year 2010, where he writes about technology, philosophy, society and a bit about physics. He now runs a conversational AI company - DheeYantra - focusing his efforts to help businesses improve operational efficiency using digital employees powered by AI.