When we were developing Vaadin applications, we were feeling excited about how the development of a user interface was easy. We could play with the UI and still think about it as object structures in Java.
Then we started to think over how beneficial integrating Spring framework into Vaadin could be. We needed dependency injection, AOP and JPA. But it was too annoying to do all the configuration manually.
Another thing we did not like was mapping classes to relational database via Hibernate. The time and energy wasted with changing the database model was bigger than we were willing to sacrifice.
There were still two things that we needed to solve in our Vaadin projects. Localization and support for various environments like development, test or production.
In the end we came across Grails. It is a Java based web application framework using Groovy language, Hibernate and Spring. Grails is based on plugins and therefore, it is pretty easy to make extensions and integrate it with other frameworks like Vaadin in this case.
Why do we think that Grails is the best option for developing and running Vaadin applications?
All we need is to follow certain conventions and Grails will help us a lot. Once you put a Groovy class into the proper folder, Grails makes persistent domain objects or transactional services for us. During the development of Vaadin applications, we are going to work with these two folders:
- grails-app/domain the classes in this folder are automatically mapped to a relational database via Hibernate.
- grails-app/service all the classes ending with Service are transformed to transactional services.
There is a configuration file BuildConfig.groovy in which we declare all the dependencies and more that affects building a .war file, a compilation or running a Grails application.
In order to setup database credentials per environment, we need to update DataSource.groovy file. Development, test and production environments are preconfigured by default to use H2 in-memory databases. Neither an installation nor a creation of a database is needed. We can start developing immediately after a project creation.
Localization properties files are placed in grails-app/i18n folder and accessible via MessageSource bean from Spring. Vaadin plugin makes it easy to access localized values via method Grails.i18n().
We have prepared a few tutorials for you to start with. These are accessible on https://vaadin.com/wiki/-/wiki/Main/Coding under Grails integration section. Hope you like it.
Ondrej Kvasnovsky is the author of Vaadin 7 Cookbook and Vaadin on Grails. You can follow @okvasnovsky personally or @VaadinOnGrails to get the latest news about the plugin.