我有 3 个问题:
Vaadin 中的每个 Action 都会调用服务器。有没有办法避免每次操作都调用服务器?比如在客户端有一个代码用于多次使用的特定操作?就像在 CSValidation 附加组件中一样。
我想知道如何在 Vaadin 7 中添加 Javascript/JQuery。在 Vaadin 6 中似乎很容易。但是,我无法在 Vaadin 7 中使用它。我希望他们现在可以使它更容易.谁能给我看一些关于这方面的例子。如果它是 JQuery,它将对我有很大帮助。
也将
Javascript.getCurrent().execute("");
在代码中“执行 javascript”或“添加指定脚本”。这会帮助我解决第二个问题吗?
最佳答案
1) Each and every action in Vaadin makes a call to the server. Is there a way to avoid calls to server for every actions? like having a code at client side for particular actions that is used many times? Like in CSValidation add-on.
这取决于客户端代码。 Vaadin 是用服务器端编程模型构建的,但是如果你需要限制服务器调用的数量,你需要自己做。与 Vaadin 6 中一样,Vaadin 7 使包含第三方库变得相对容易。
2) I want to know how to add Javascript/JQuery in Vaadin 7. It seems easy in Vaadin 6. But, I couldn't get it working in Vaadin 7. I hope they would have made it more easy now. Can anyone show me some examples regarding this. If it is JQuery, It will help me a lot.
这里有一个很好的教程,介绍如何将 jQuery 与 Vaadin 7 集成:http://java.dzone.com/articles/integrating-html-and-0
基本上是创建一个 JavascriptExtension 类,这是解决方案的主要部分:
@JavaScript({ "https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.js" })
public class JavascriptJQueryExtension extends AbstractJavaScriptExtension {
... // Please see the link above for an example of implementation
}
路径可以是 URL 或 jQuery 库的内部路径。
3) 'execute the javascript' or 'add specified script' in to the code.
将执行以下代码片段,如 Book of Vaadin 7 ( https://vaadin.com/book/vaadin7/-/page/advanced.javascript.html ) 中所述
// Shorthand
JavaScript.getCurrent().execute("alert('Hello')");
The JavaScript is executed after the server request that is currently processed returns. (...)
我建议您好好看看 Vaadin 之书。它包含许多重要信息,通常有助于解决使用 Vaadin 时出现的大多数问题。
关于java - 在 Vaadin 7 中添加 javascript/Jquery 和客户端代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17217536/