Close

Vaadin 8 roadshow wrap up

Vaadin 8 simplifies the development of web apps for Java developers like never before. 
We wanted to spread the word, so we visited tens of JUGs and Vaadin meetup groups this spring.

Following the major Vaadin 8 release in February, we have been traveling the world - In practice mostly Europe and US. We visited almost 20 places from Spain to St. Louis and talked with hundreds of Java developers. As one of our attendees put it: "Web page made with frontend and backend in less than 30 minutes! #Java #vaadin #vaadin8"

"I've developed a demo app using Vaadin Spring Boot within 3 days after DJUG meeting, and the features include @Push WebSocket, Navigation UI with(2 Views, and Grids. It's very cool."

"Vaadin is a pretty cool platform for spinning up a quality web app. Thanks again for the meet-up!"

"It looks like Vaadin removes a ton of the grunt work associated with web development. I like how it integrates nicely with the Spring ecosystem. It would make life a lot easier on developers (and save companies A LOT of money) if frameworks like this would get traction in the United States."

Did you miss us? No problem. Just let us know where you would like to see us, and we'll think of something. See you!
 

Vaadin ♡ Kotlin

Kotlin, the new kid in the family of JVM-based languages, is slowly but steadily capturing hearts of many Java developers. All the while finding its way to many prominent Java-related projects, such as Android, Spring and Gradle. It is indeed possible to use Vaadin with Kotlin as well!

I recently wrote a series of articles which not only explain the ideas behind the Vaadin DSL and JPA integration, but also explores ways of Kotlin language features replacing the traditional Spring/JavaEE approach.

1. The DSL

For the impatient, here is a taste of how Vaadin would benefit from having Kotlin support. First, DSL, or Domain Specific Language, or writing your UI in Kotlin:

@AutoView
class CrudView: VerticalLayout(), View {
  // you can restrict the values by writing the following expression.
  // This is an example of a SQL DSL:
  private val personsDataProvider = jpaDataProvider<Person>()
     .and { Person::age between 20..60 }

  init {
    setSizeFull()
    horizontalLayout {
      createButton = button("Create New Person (Ctrl+Alt+C)") {
        onLeftClick { 
          createOrEditPerson(Person(created = Date())) 
        }
        clickShortcut = Ctrl + Alt + C
      }
      button("Generate testing data", { generateTestingData() })
    }
    // the JPA list demo - shows all instances of a particular JPA entity,
    // allow sorting and filtering
    personGrid = grid(Person::class, dataProvider = personsDataProvider) {
      expandRatio = 1f; setSizeFull()
      // example of a custom renderer which converts value to a
      // displayable string.
      column(Person::created) {
        setConvertingRenderer { it!!.toInstant().toString() }
      }
      // show these columns, and in this order. Note the static
      // Person property references
      showColumns(Person::id, Person::name, Person::age, 
          Person::dateOfBirth, Person::maritalStatus, Person::alive,
          Person::created)
      // add additional columns with buttons
      addColumn({ "Show" }, ButtonRenderer<Person>(
          { event -> PersonView.navigateTo(event.item) }))
      addColumn({ "Edit" }, ButtonRenderer<Person>(
          { event -> createOrEditPerson(event.item) }))
      addColumn({ "Delete" }, ButtonRenderer<Person>(
          { event -> deletePerson(event.item.id!!) }))
      // you can even auto-generate filter bar.
    }
  }
}

This code produces the following UI:

(This is taken from Vaadin-on-Kotlin's example project: CrudView.kt, so you can already explore these ideas for yourself)

The advantage of using Kotlin DSL over defining the UI via Java code is the inherently visible structure - it is clear how components are nested in one another. That is the same advantage that is often said to be an advantage of markup languages over Java code. The advantage over Design htmls is that this is statically-typed Kotlin code, so the compiler will check the correctness for us, and there is no need to waste CPU cycles to parse the html. You can also use any for loops and parametrization as you like, and you can easily employ I18N.

The Kotlin DSL code may look undecipherable at first, but what if Vaadin Designer could render a read-only view of this view?

2. Database Access

Using blocks, you can define a db function which will run given block in a transaction, thus allowing you to write the Delete button as follows:

button("Delete") {
  onClick { db { em.delete(person) } }
}

Or attach find methods directly to your JPA entities:

@Entity
data class Person(...) {
  companion object {
    fun findAll(): List<Person> = db { em.findAll<Person>() }
    fun findByName(name: String): List<Person> = db {
      em.createQuery("...").resultList 
    }
  }
}

This will allow you to write expressions like val zaphods = Person.findByName("Zaphod") and helps you avoid the necessity of creating @Transactional DAOs.

3. Service directory and discovery

You can use Kotlin's extension mechanism to attach properties to a pre-agreed object. Think the Services object (and Session object) in a common project:

object Services {}
object Session {}

Every module can then add a service simply as follows:

val Services.weatherForecast: WeatherForecastService get() = ...
val Session.loggedInUser: User get() = ...

You just fire up your IDE, write Services., press Ctrl+Space and watch the IDE Kotlin plugin do the magic and auto-complete the services for you. No further need for injections!

There are also a couple of interesting efforts to bring an even better Kotlin experience to Vaadin:

  1. The Kaadin library - an open-source so-called DSL library to create Vaadin UIs in pure Kotlin. The Kaadin page at https://nfrankel.github.io/kaadin/ lists many interesting examples of DSL-modeled UIs. Supports Vaadin 7.7.x

  2. The Karibu-DSL is also a DSL library, but it targets Vaadin 8.1.x instead. You can check out the online demo of the example application.

  3. Vaadin-on-Kotlin is a more complete way of creating apps with Vaadin and Kotlin, since it not only offers Vaadin DSL, but it also allows for integration with JPA (both DataProvider and JPAContainer), publishing your own REST services, and allows you to build a complete web app running on pure Servlet containers. Supports Vaadin 8.x including v7 compatibility mode.

If you’d like to shape the future of Vaadin-Kotlin integration, please join the development of those libraries. Just trying them out and providing bug reports or enhancement requests is the easiest way to join the effort!

Read the full Vaadin apps in Kotlin tutorial

Community Spotlight - May 2017

For this month’s Community Spotlight I had the pleasure of talking with Nicolas Frankel, published author (Learning Vaadin, Learning Vaadin 7, and Integration Testing from the Trenches), developer, speaker, influencer, and passionate about technology. Find out his thoughts about Vaadin and what makes it a unique web framework.

Hi, Nicolas. It's great to speak with you! You have one of those names that Vaadin and Java developers recognize. What are you working on at the moment? Any books or open-source projects going on?

Hey Alejandro, thanks for the invite.

The last few years, I chose to involve myself by talking at different international conferences. This, unfortunately, doesn't leave much time to commit to projects, books or otherwise. Still, I started the Kaadin project that provides an easy-to-use Kotlin DSL to define Vaadin components.

Two of your books are about Vaadin, what motivated you to write them? Why Vaadin? 

At the time of the first book, the only Vaadin documentation available was the official "Book of Vaadin" and the API. Those were great, but there was no easy step-by-step path "from zero to hero". When Joonas told me Packt was searching for a writer, I jumped at the chance.

About the Vaadin framework, I believe it occupies a unique niche among Java Web frameworks. There's no competitor offering a true Object Oriented approach that allows for easy reuse. Plus your team only needs to know the Java language, and it's possible to truly parallelize your CSS/HTML templates customization with backend development. From a ROI perspective, nothing beats Vaadin for business apps development.

What would you say is the most important change you have seen in the Vaadin Community and its open-source products in the last years?

From the Finnish IT Mill company centered around one single product, Vaadin has become a true international player in the software ecosystem. It took responsibility in the stewardship of GWT, and provided an entire new product, Vaadin Web Elements. In short, you're able to reinvent yourself constantly. That's rare and precious.

How about the future? How do you see Vaadin in the future or how you would like it to be?

I'd like to see more integration, like the Spring Boot Vaadin starter. A framework, and especially a web framework, is only as good as the integration points it offers. There's JPA, Hibernate, Spring Boot, Liferay, but I believe more can be done in this area - especially since some of them are provided by the community.

What do you think about the improvements added in Vaadin 8? What's your favorite new feature in Vaadin 8? 

Oh, the tricky question. I'm nothing but honest, and I haven't played with Vaadin 8 much so far. But using lambdas from Java 8 are definitely a step in the right direction. And having worked with Matti on an add-on to integrate the History API last summer, having it integrated into the core makes me feel all warm inside.

That was an awesome contribution! Anything else you'd like to say to the Vaadin Community?

Keep up the good work, guys. You have the coolest web framework in the world! I love you all.

We love you too Nicolas! Thanks for sharing your thoughts and best wishes with your projects

Learn how Vaadin Framework works and try it today!