了解 Vaadin 如何使用 GWT [英] Unterstanding how Vaadin uses GWT

查看:20
本文介绍了了解 Vaadin 如何使用 GWT的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用 Vaadin 大约一个星期后,我很好奇 Vaadin 如何使用 GWT.GWT 将 Javacode 编译为 Javascript.每次重新部署时都必须这样做.

After playing around with Vaadin for about a week I'm curious about how Vaadin uses GWT. GWT compiles Javacode to Javascript. This has to be done everytime when you are redeploying.

由于 Vaadin 必须被理解为以服务器为中心的框架,因此消除了编写在客户端执行的代码并将所有内容移动到服务器的灵活性(这听起来比实际情况更糟),GWT 编译器只运行一次时间.例如,当您从 vaadin 网站导入插件时就会发生这种情况.

Since Vaadin has to be understood as a server-centric framework, eliminating your flexibility on writing Code that is executed on Clientside and moving everything to the server (which sounds worse than it actually is), the GWT Compiler only runs once a time. For example this happens when you are importing a plugin from the vaadin website.

但这不会那么容易吧?如果它只是将插件的代码编译为 javascript,这本来可以做到的.

But it can't be that easy right? If it only would compile the code of the plugins to javascript this could have done before.

所以,我的问题是:

VAADIN 什么时候使用 GWT 编译器,此时除了编译为 js 之外,它还会做什么?

When does VAADIN use the GWT Compiler and what does it do at that point other than compiling to js?

推荐答案

基本上你是对的,而且大部分都是你自己回答的问题.

Basically you have it right, and mostly answered the question yourself.

在 Vaadin 中,用户界面组件由两部分组成:

In Vaadin the user interface components consist of two parts:

  1. 使用JDK编译的服务器端组件"
  2. 使用 GWT 编译的客户端小部件"

这些部分通过 HTTP 相互通信,并根据需要自动同步它们的状态.服务器端部分维护用户界面组件的状态,客户端小部件呈现该状态.

These parts communicate with each other over HTTP and automatically synchronize their state as needed. Server-side part maintains the state of the user interface component and the client-side widget renders that state.

应用程序开发人员通常只使用服务器端组件来构建应用程序,他们并不真正关心客户端的工作方式.

Application developers typically only use the server-side components to build the application and they don't really have to care about how the client-side works.

一般来说,Vaadin 的新组件可以通过两种方式开发:

In general, new components to Vaadin can be developed in two ways:

  1. 组合现有组件
  2. 使用 GWT/JavaScript(+ 其他客户端技术)创建新的小部件

这里的第一种方法使用现有的类,不需要使用 GWT 重新编译小部件.仅编译应用程序代码(使用 JDK 编译器).但是,在第二种情况下,客户端类发生了变化,需要重新编译.这是需要 GWT 编译器的时候.

The first method here uses the existing classes and don't need recompilation of the widgets with GWT. Only the application code is compiled (with JDK compiler). However, in the second scenario the client-side classes change and need recompilation. This is when the GWT compiler is needed.

由于 GWT 编译的 JavaScript 相当单一的性质(无论 GWT 的新代码拆分功能如何,命名空间都是全局的)Vaadin 使用 widget set 的概念.这是一个 GWT 模块,包含应用程序中所需的所有小部件.这意味着向应用程序添加新的(客户端)小部件需要 GWT 重新编译.删除widget时重新编译widget set也是一个不错的做法,可以优化widget set的大小.

Due to the rather monolithic nature of the GWT compiled JavaScript (regardless of new code splitting features of GWT the namespace is global) Vaadin uses the concept of widget set. That is a GWT module that contains all the widgets needed in the application. That means that adding new (client-side) widgets to an application a GWT recompilation is needed. It is also a good practice to recompile widget set when removing widgets to optimize the widget set size.

GWT 编译步骤本身没什么特别的.但是,Vaadin 本身包含了许多由小部件应用和使用的 GWT 类的添加、帮助程序和解决方法.

GWT compilation step itself is nothing special. However, Vaadin itself contains lot of additions, helpers and workaround to GWT classes that are applied and used by the widgets.

使用 Vaadin 附加组件时,所有这些都非常明显(请参阅 http://vaadin.com/directory).即使插件只是简单的 jar 文件,如果它们包含新的客户端小部件代码,则在将它们添加到项目时需要使用 GWT 编译小部件集.

All this is quite visible when using Vaadin add-ons (see http://vaadin.com/directory). Even add-on are simply jar-files, if they contain a new client-side widget code, widget set compilation using GWT is needed, when they are added to a project.

这篇关于了解 Vaadin 如何使用 GWT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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