问题
I've read the other posts regarding this topic already. I just want to clarify, is there really no way in vaadin to:
- Create a custom layout html file, like custom.html;
- Import a java script file to it, then...;
- Call the js functions from within the html file, like one would normally?
Currently I have home.html in my Vaadin\themes(project)\layouts and a javascript library in Vaadin\js\custom.js.
In my Panel class i have annotation @JavaScript({"vaadin://js/custom.js"})
, and in my html i tried <script type="text/javascript" src="custom.js"></script>
.
I have in the html file some hyperlinks, that need to call the js functions when clicked.
Any info if this is possible, would be most helpful?
回答1:
Its not possible to call it directly from your html layout. Notice that your custom html file its only a layout thus Vaadin generates his own html using your layout AND server side code. Thats why your <script>
annotation is not only redundant - it is simply useless.
However its still possible to call JavaScript using Vaadin. Using listeners you can call client-side code from the server:
ok.addClickListener(new ClickListener()
{
@Override
public void buttonClick(ClickEvent event)
{
JavaScript.getCurrent().execute("itsHot()");
}
});
来源:https://stackoverflow.com/questions/30307205/vaadin-adding-javascript-to-custom-layout