Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unterstanding how Vaadin uses 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?

like image 401
Benjamin Brandmeier Avatar asked Aug 19 '11 16:08

Benjamin Brandmeier


People also ask

Does Vaadin use GWT?

Vaadin used GWT to build a full fledged application framework. It is one of the main GWT based frameworks ( along with Errai framework) and provides some interesting capabilities like addons, themes, integrations with other Java frameworks such as Spring.

What is Vaadin used for?

Vaadin Framework is a Java web application development framework that is designed to make creation and maintenance of high quality web-based user interfaces easy. Vaadin supports two different programming models: server-side and client-side. The server-driven programming model is the more powerful one.

Is Vaadin framework good?

So, the Vaadin framework has higher scalability than the conventional JavaScript-based application. The Vaadin is faster than the XML-based application because of using JSON. Separate components such as CSS and themes can be used to provide amazing customer-side feedback.


1 Answers

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.

like image 145
eeq Avatar answered Sep 23 '22 03:09

eeq