Important Notice - Forums is archived
To simplify things and help our users to be more productive, we have archived the current forum and focus our efforts on helping developers on Stack Overflow. You can post new questions on Stack Overflow or join our Discord channel.

TUTORIALVaadin lets you build secure, UX-first PWAs entirely in Java.
Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.
Calling javascript synchronously by Enver Haase, 4 weeks ago
Vaadin + 3rd party lib chat service
Hello,
how to add 3rd party live chat window into Vaadin app?
I would like to use Smartsupp.com. Usually Smartsupp integration consist in adding this part:
<!-- SmartSupp Live Chat script -->
<script type="text/javascript">
var _smartsupp = _smartsupp || {};
_smartsupp.key = '57a32598h68b294a6a4615f30hbd4c85a946bfa0';
window.smartsupp||(function(d) {
var s,c,o=smartsupp=function(){ o._.push(arguments)};o._=;
s=d.getElementsByTagName('script')[0];c=d.createElement('script');
c.type='text/javascript';c.charset='utf-8';c.async=true;
c.src='//www.smartsuppchat.com/loader.js?';s.parentNode.insertBefore(c,s);
})(document);
</script>
between <head> and </head>.
Is this possible in Vaadin?
I use Vaadin 7.5.6. and Vaadin Spring 1.0.0.beta1
Thanks.
Last updated on
I found solution.
Create a custom servlet that extend the SpringVaadinServlet:
import javax.servlet.ServletException;
import com.vaadin.server.BootstrapFragmentResponse;
import com.vaadin.server.BootstrapListener;
import com.vaadin.server.BootstrapPageResponse;
import com.vaadin.server.ServiceException;
import com.vaadin.server.SessionInitEvent;
import com.vaadin.server.SessionInitListener;
import com.vaadin.spring.server.SpringVaadinServlet;
@SuppressWarnings("serial")
public class MyServlet extends SpringVaadinServlet {
@Override
protected final void servletInitialized() throws ServletException {
super.servletInitialized();
getService().addSessionInitListener(new SessionInitListener() {
@Override
public void sessionInit(SessionInitEvent sessionInitEvent) throws ServiceException {
sessionInitEvent.getSession().addBootstrapListener(new BootstrapListener() {
@Override
public void modifyBootstrapPage(final BootstrapPageResponse response) {
response
.getDocument()
.head()
.append(
"<!-- Start of Smartsupp Live Chat script -->" + //
"<script type=\"text/javascript\">" + //
"var _smartsupp = _smartsupp || {};" + //
"_smartsupp.key = \"57a32598f68b294a6a4615f300bd4c85a946bfa0\";" + //
"window.smartsupp||(function(d) {" + //
" var s,c,o=smartsupp=function(){ o._.push(arguments)};o._=;" + //
" s=d.getElementsByTagName('script')[0];c=d.createElement('script');" + //
" c.type='text/javascript';c.charset='utf-8';c.async=true;" + //
" c.src='//www.smartsuppchat.com/loader.js';s.parentNode.insertBefore(c,s);" + //
"})(document);" + //
"</script>" + //
"<!-- End of Smartsupp Live Chat script -->");
}
@Override
public void modifyBootstrapFragment(BootstrapFragmentResponse response) {
}
});
}
});
}
}
In child of UI change servlet:
@WebServlet(value = "/*", asyncSupported = true)
public static class Servlet extends MyServlet {
private static final long serialVersionUID = 1L;
}
Last updated on
You cannot reply to this thread.