I am trying to call a custom javascript function but I cannot seem to get the js file to be included.
I have the javascript file in:
/frontend/js/myfunc.js
containing:
var NS =
{
testJS: function (id)
{
console.log('NS::testJS - ' + id);
}
}
and have added the annotation to my main class:
@JavaScript("./js/myfunc.js")
However, the following shows an error in the console (Uncaught ReferenceError: NS is not defined):
Page page = UI.getCurrent().getPage();
page.executeJs("NS.testJS($0);", "Bob");
The following code works as expected:
Page page = UI.getCurrent().getPage();
page.executeJs("console.log($0);", "Bob");
The above javascript is just a simple test case to demonstrate the issue.
Running Vaadin 14.1.3 and Spring Boot 2.2.2.