Java UI framework Vaadin releases version 8

After a long period of development, Vaadin Ltd has released version 8 of the Vaadin Java UI framework with a slew of new features.  The most notable changes can be found in the data binding API of the framework.

Based on Java 8, the latest Vaadin 8 release takes advantage of lambda expressions introduced in Java 8 to make data binding much much expressive and easy.

For instance, in the past, one needed a Container interface implementation to pass objects to the Grid component thus

List persons = Backend.getPersons();
BeanItemContainer container =
new BeanItemContainer(Person.class, persons);
Grid grid = new Grid();
grid.setContainerDataSource(container);

now becomes

List persons = Backend.getPersons();
Grid grid = new Grid<>(Person.class);
grid.setItems(persons);

I am personally very excited about this release because hitherto one had to rely on Matti Tahvonen’s Viritin addon to overcome the very verbose databinding Vaadin APIs.

Another awesome feature is that Vaadin 8 will now support the browser history API, meaning much more cleaner and search engine friendly URLs. Essentially no more hashbang (#!) in the URLs.

Demonstrating support for HTML5 History API

 

Another area that has received updates is captions generators. In the past, one had to write

List persons = Backend.getPersons();
ComboBox comboBox = new ComboBox();
BeanItemContainer bic =
new BeanItemContainer<>(persons);
GeneratedPropertyContainer gpc =
new GeneratedPropertyContainer(bic);
gpc.addGeneratedProperty("name",
new PropertyValueGenerator() {
@Override
public String getValue(
Item i, Object id, Object o1) {
Person p = (Person) id;
return
p.getFirstName() + " " + p.getLastName();
}

@Override
public Class getType() {
return String.class;
}

@Override
public Container.Filter
modifyFilter(Container.Filter filter)
throws UnsupportedFilterException {
final SimpleStringFilter ssf =
(SimpleStringFilter) filter;
return new Container.Filter() {
@Override
public boolean passesFilter(
Object itemId, Item item)
throws UnsupportedOperationException {
final Item genItem = gpc.getItem(itemId);
String fullname =
genItem.getItemProperty("name")
.getValue().toString();
return fullname.toLowerCase().startsWith(
ssf.getFilterString());
}
@Override
public boolean appliesToProperty(
Object propertyId) {
return "name".equals(propertyId);
}
}
}
});
comboBox.setItemCaptionPropertyId("name");
comboBox.setContainerDataSource(gpc);

to generate caption for items in a ComboBox. With the new release, you just write

List persons = Backend.getPersons();
ComboBox comboBox = new ComboBox<>();
comboBox.setItemCaptionGenerator(
p -> p.getFirstName() + " " + p.getLastName()
);
comboBox.setItems(persons);

These are just a few of the latest features available in Vaadin Java UI Framework version 8. You can find an overview of the new changes here. This new version will make writing modern, HTML 5 UIs in plain java a real joy. I cannot wait to start cranking code with Vaadin 8.

Leave a Reply

Your email address will not be published. Required fields are marked *