Unterstanding how Vaadin uses GWT

て烟熏妆下的殇ゞ 提交于 2019-11-30 03:15:18

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/7124528/unterstanding-how-vaadin-uses-gwt

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!