Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.


GitHub tag Heroku

VoK-CRUD Example application

A more complete full-stack example application which you can inspire from. You can launch the app simply from your terminal:

git clone https://github.com/mvysny/vaadin-on-kotlin
cd vaadin-on-kotlin
./gradlew vok-example-crud-sql2o:appRun

The web app will be running at http://localhost:8080.

You can find the VoK-CRUD Live Demo running on Heroku.

The app is a standard WAR application. Just import the whole vaadin-on-kotlin project directly into your IDE, then launch this app as a WAR application in the servlet container of your choice.

Behind The Scenes

The application demonstrates the following things:

  • Linking to a database. VaadinOnKotlin uses vok-orm for simple O/R mapping when accessing the database. The example project is simply using an in-memory H2 database, so that no additional setup is necessary. See build.gradle the db section for more details. To link to the database, we configure Hikari database connection pooler in Bootstrap.kt. HikariCP provides production-grade performance. You can also use JPA if you so wish - see vok-example-crud-jpa for details.
  • Preparing the database: simply run Flyway migration every time before the app is started, to make sure that the app has newest database ready. The migration is safe on cluster as well as a database lock is obtained. Please see Bootstrap.kt You will need to write the database migration scripts yourself: see sample migrations for details. More details in the Flyway DB Migration Guide
  • Accessing the database: just create your pojo beans (example Person) and use them in any way you see fit: val allPersons = db { Person.findAll() }. The db is just a function defined in the vok-orm framework. You can call the db{} method from anywhere, be it Vaadin click listener or background thread. No injections/beans/EJBs/whatever necessary! See the vok-orm documentation for more details.
  • Serving the data via REST: add vok-rest to your project, see build.gradle. Then, declare REST Application to bind the REST to a particular URL endpoint, see Bootstrap.kt the @ApplicationPath("/rest") stanza. After that, just define your REST-accessing classes, for example PersonRest
  • Creating the UI: there are lots of great Vaadin tutorials, in general you declare UI and populate it with components. See MyUI
  • Create Update Delete (CRUD): no Scaffolding-like UI generator for now, but you can see the crud example on how to write the CRUD UI yourself very easily.
  • Logging: uses SLF4j with Logback, configured as follows: logback.xml
  • Session-stored cache which of course can access database anytime: see LastAddedPersonCache.kt.
  • Running: this app is a standard WAR application which you can run from your IDE directly.
  • Testing: uses the Karibu-Testing framework; please find the example test at CrudViewTest.kt.