java - Vaadin: adding a custom javascript to bootstrap page -
this question has answer here:
i need add jquery bootstrap page of vaadin application. added following in custom servlet
class
@override public void sessioninit(sessioninitevent event) throws serviceexception { event.getsession().addbootstraplistener(new bootstraplistener() { @override public void modifybootstrappage(bootstrappageresponse response) { //jquery necessary open in new window button string contextpath = event.getrequest().getcontextpath(); response.getdocument().head().prependelement("script").attr("type", "text/javascript").attr("src", contextpath + "/vaadin/js/jquery.min.js"); response.getdocument().head().prependelement("script").attr("type", "text/javascript").attr("src", contextpath + "/vaadin/js/jquery-ui.js"); } @override public void modifybootstrapfragment(bootstrapfragmentresponse response) { } }); }
this code throws null pointer exception in event.getrequest().getcontextpath();
caused by: java.lang.nullpointerexception @ org.apache.catalina.connector.request.getservletcontext(request.java:1598) ~[catalina.jar:8.0.24] @ org.apache.catalina.connector.request.getcontextpath(request.java:1915) ~[catalina.jar:8.0.24] @ org.apache.catalina.connector.requestfacade.getcontextpath(requestfacade.java:783) ~[catalina.jar:8.0.24] @ javax.servlet.http.httpservletrequestwrapper.getcontextpath(httpservletrequestwrapper.java:150) ~[servlet-api.jar:?] @ com.mycompany.myservlet$1.modifybootstrappage(yaanservlet.java:56) ~[web-yaan-ui-base-1.3.39.jar:?]
what correct way context path in situation?
a simpler way use @javsscript annotation on ui class
package com.company.mine; @javascript({"jquery.min.js","jquery-ui.js"}) public class yourui extends ui { }
you need put 2 javascript files folder matching class of yourui. use maven need in src/main/resources/com/company/mine/jquery.min.js
Comments
Post a Comment