问题
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:
- Server-side "component" compiled using JDK
- 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:
- Composing existing components
- 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