vaadin-8-new-version

Vaadin 8, the new version of the Java framework for web applications and its features

Since a few weeks ago we have available a new version of Vaadin, the Java framework for web application development. In today’s post we have decided to make a list of the main changes that Vaadin 8 presents with respect to the previous version. We’ll tell you.

Vaadin is a Java framework that is used for the development of web applications, allowing them to have a pleasant and modern appearance. More and more developers use it, given the advantages that it brings, that is why today we decided to take a closer look at the advantages offered by this new version in relation to the previous one.

In this new version, 8, many performance improvements (in some cases with an order of magnitude up to 10 times more efficient!) are added, as well as a lot of improvements to facilitate the work of the developer in very common tasks. Now it’s even easier to do things!

One of the biggest structural changes is the use of Java 8, which opens the door to the use of the functionalities inherent of this language version: lambda expressions, streams, etc.

1.- It allows to pass lists of objects directly to Grid and Select type components

Before, to load data inside a Grid, ComboBox, etc type component. It was necessary to appeal to some implementation of the Container interface. Now, with Vaadin 8, we can directly pass a list of objects to these components:

List<Person>people = Backend.getPersons();

Grid<Person>grid = new Grid<>(Person.class);

grid.setItems(people);

2.- Create captions for the elements of a Select

A very common task is to show in our components of type Select a visual value different from the internal value of the contained object. Or even display a visual value composed of two attributes of a bean. For that, in Vaadin 8 they have introduced the Item Caption Generator:

List<Person>people = Backend.getPersons();

ComboBox<Person>comboBox = new ComboBox<>();

comboBox.setItemCaptionGenerator(

p ->p.getFirstName() + ” ” + p.getLastName() + “(“+ p.getAge() +”)”

);

comboBox.setItems(people);

3.- Definition of Grid columns

The definition of the columns of the Grid-type components has been improved and simplified. Now it is much simpler, typesafe and readable:

Grid<Person>grid = new Grid<>();

grid.setItems(persons);

grid.addColumn(Person::getFirstName).setCaption(“FirstName”);

grid.addColumn(Person::getLastName).setCaption(“LastName”);

4.- Lazyloading

In previous versions, in order to efficiently load data without overloading the server, it was mandatory to implement a complex interface Container type. Now, implementing a progressive data load is much simpler:

Grid<Person>grid = new Grid<>();

grid.setDataProvider(

   (sortorder, offset, limit) ->service.findAll(offset, limit),

   () ->service.count()

);

5.- Converters with lambda expressions

Using lambda expressions we can define converters directly, in a readable and concise way:

newBinder<Person>().forField(textField)

   .withConverter(

textToInteger ->Integer.parseInt(textToInteger),

integerToText ->integerToText.toString()

   )

   .bind(“age”);

6.-Add components and expand them automatically

Something to which we are very use to, the ones that we have been using Vaadin from prior versions to the 8 is to expand components after having inserted them in the corresponding layout. Now, at last, we can do it in one step!

HorizontalLayoutheader = new HorizontalLayout(title, logout);

VerticalLayoutroot = new VerticalLayout(header);

Grid<Person>grid = new Grid<>();

root.addComponentsAndExpand(grid);

7- Margins and spacing activated by default in the layout

Another thing that had to be done by hand in all (or almost all) layouts, was to activate the margins and spacing. Now these values come active by default in the most used layouts (VerticalLayout and HorizontalLayout), saving us code and time and, by the way, helping to have something aesthetically pleasing without much head heating.

8.- Compatibility package with previous versions

To use Vaadin 8 in an existing application with a previous version, a migration package

Have been provided through a Maven task, so updating is something as simple as executing the following at the root of the project:

mvn vaadin:upgrade8

So far we have reviewed the main features of Vaadin 8, we hope they have been useful.

We’ll be back next week.