Hi!
I know, one can create custom JS components to use in screens.
But, unfortunately, it’s not what I need.
So, what’s the proper way to add a custom JS file globally, to use it for theming purposes?
Many thanks in advance!
Hi!
I know, one can create custom JS components to use in screens.
But, unfortunately, it’s not what I need.
So, what’s the proper way to add a custom JS file globally, to use it for theming purposes?
Many thanks in advance!
What I have now:
PS: I am OK with this solution, but was wondering if there is an appropriate one.
Thanks.
Hi,
In order to include JS globally, you can create a bean that extends CubaBootstrapListener
:
public class MyBootstrapListener extends CubaBootstrapListener {
@Override
public void modifyBootstrapPage(BootstrapPageResponse response) {
super.modifyBootstrapPage(response);
Element head = response.getDocument().getElementsByTag("head").get(0);
// Include JS to HTML, for example: "VAADIN/webjars/mylib/0.1/lib.js"
String pathToLib = "VAADIN/webjars/path/to/webjar/resource";
includeScript(pathToLib, response, head);
}
Register it in web-spring.xml
:
<bean id="cuba_BootstrapListener"
class="com.company.demo.web.manifest.MyBootstrapListener"/>
Hi, Yuriy. Thanks for the reply.
I am using CUBA v 6.10 and I have no such class “CubaBootstrapListener” to extend.
Are you referring to the newer version?
It is com.haulmont.cuba.web.sys.CubaBootstrapListener
: