Image for post
Image for post

Vaadin 8 in Kotlin: Data model changes — ComboBox, Grid …

David Marko
Feb 7, 2017 · 2 min read

There are many nice features promised to come with Vaadin version 8. You probably know that Vaadin 8 is JDK 1.8 optimized version and many related simplifications are available in API now. Lets look at some nice features related to data model closely. All examples below are created using Kotlin syntax.

ComboBox Items
Data source for ComboBox can be defined as a simple list of beans using setItems methods. Caption for ComboBox items displayed in browser can be defined as generator using setItemCaptionGenerator method. Its a real simplification as we can define lambda for caption computation from bean properties.

Kotlin language also brings some simplification by using ‘.apply’ method. We have less and more compact code.

Grid — data providers
To set items for Grid component we can call setItems(listOf()) the same way we did for ComboBox above. But Grid component usually requires dynamic data, where we can add , remove or modify items and see Grid to refresh content by following our changes. For this purpose we can define DataProvider that loads our data from list. Now, whenever we update our gridData list, we can then call grid.dataProvider.refreshAll() to let Grid refresh items on screen. So simple and straightforward.

With Kotlin we used mutableListOf(…) to create list of beans quickly and ‘.apply’ to define Grid properties in one closed code block. The code looks quite nice and is easy to understand.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch

Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore

Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store