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

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

问题描述

在与Vaadin玩了大约一周之后,我对Vaadin如何使用GWT感到好奇。 GWT将Javacode编译为Javascript。这必须在每次重新部署时完成。



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



但是它不是那么容易吗?如果它只是将插件的代码编译为JavaScript,则可以在之前完成。



所以,我的问题是:



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

解决方案

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



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


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

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

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



    通常,Vaadin的新组件可以通过两种方式开发:


    1. 编写现有组件

    2. 使用GWT / JavaScript(+其他客户端技术)创建新窗口小部件

    这里的第一种方法使用现有的类,不需要使用GWT重新编译小部件。只有应用程序代码被编译(使用JDK编译器)。但是,在第二种情况下,客户端类更改并需要重新编译。这是在需要GWT编译器的情况下。



    由于GWT编译的JavaScript相当单一的特性(不管GWT的新代码分割特性如何,名称空间是全局的)Vaadin使用小部件集的概念。这是一个包含应用程序中所需的所有小部件的GWT模块。这意味着需要为应用程序添加新的(客户端)小部件,以便进行GWT重新编译。在移除小部件以优化小部件集大小时,重新编译小部件集也是一个很好的做法。

    GWT编译步骤本身并不特别。但是,Vaadin本身包含了很多附加,辅助和解决方法,以适用于小部件应用和使用的GWT类。

    使用Vaadin加载项时,所有这些都很明显(请参阅 http ://vaadin.com/directory )。即使插件也只是jar文件,如果它们包含新的客户端小部件代码,那么当它们被添加到项目中时,需要使用GWT进行小部件集编译。


    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.

    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.

    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.

    So, my question is:

    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.

    In Vaadin the user interface components consist of two parts:

    1. Server-side "component" compiled using JDK
    2. Client-side "widget" compiled using GWT

    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.

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

    1. Composing existing components
    2. Creating a new widgets with GWT/JavaScript (+ other client-side tech)

    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.

    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 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.

    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天全站免登陆