添加javascript / Jquery& Vaadin 7中的客户端代码 [英] Add javascript/Jquery & client side code in Vaadin 7

查看:110
本文介绍了添加javascript / Jquery& Vaadin 7中的客户端代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有3个问题:


  1. Vaadin中的每一个动作都会调用服务器。有没有办法避免每个动作调用服务器?比如在客户端有代码用于多次使用的特定操作?就像在CSValidation插件中一样。

  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 7中添加Javascript / JQuery。在Vaadin 6中似乎很容易。但是,我不能不能让它在Vaadin 7工作。我希望他们现在能让它更容易。谁能告诉我一些关于这方面的例子。如果它是JQuery,它将对我有很大的帮助。

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.

并且

Javascript。 getCurrent()。execute();

Javascript.getCurrent().execute("");

'执行javascript'或'添加指定的脚本'到代码。这有助于我解决第二个问题吗?

'execute the javascript' or 'add specified script' in to the code. Will this help me to solve my 2nd question?

推荐答案


1)Vaadin中的每一个动作拨打服务器。有没有办法避免每次操作都调用服务器?比如在客户端有代码用于多次使用的特定操作?与CSValidation附加组件类似。

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 7使得包含第三方库变得相对容易,因为它在Vaadin 6中。

This depends on the client-side code. Vaadin is built with a server side programming model, but if you need to restrict the amount of server calls, you need to do it yourself. Vaadin 7 made it relatively easier to include third party libraries as it was in Vaadin 6.


2)我想知道如何添加Javascript在Vaadin 7中的/ JQuery。在Vaadin 6中看起来很容易
。但是,我无法让它在Vaadin 7中工作。我希望他们
会让它变得更加容易。任何人都可以给我看一些关于这个的例子
。如果它是JQuery,它将对我有很大的帮助。

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

Here you have a nice tutorial on how to integrate jQuery with Vaadin 7: http://java.dzone.com/articles/integrating-html-and-0

它基本上是创建一个JavascriptExtension类,这是解决方案的主要部分:

It basically goes about creating a JavascriptExtension class, this is the main part of the solution:

@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库的内部路径。

The path can either be an URL or an internal path to the jQuery library.


3)'执行javascript'或'添加指定的脚本'到代码。

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

The following code snippet will be executed, as stated in the Book of Vaadin 7 (https://vaadin.com/book/vaadin7/-/page/advanced.javascript.html)

// Shorthand
JavaScript.getCurrent().execute("alert('Hello')");




在当前$ b $的服务器请求之后执行JavaScript b处理退货。 (...)

The JavaScript is executed after the server request that is currently processed returns. (...)

我建议你好好看看Vaadin书。它包含许多重要信息,通常有助于解决使用Vaadin时出现的大多数问题。

I would suggest for you to take a good look at the Book of Vaadin. It contains a lot of important information that is usually helpful to solve most of the problems that arise when working with Vaadin.

这篇关于添加javascript / Jquery& Vaadin 7中的客户端代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆