---
title: Using Vaadin with Kotlin
order: 1100
layout: page
---

[[getting-started.kotlin]]
= Using Vaadin with Kotlin

You can use Vaadin with the link:https://kotlinlang.org/[Kotlin] language as well. Kotlin offers
awesome tooling which includes a plugin for Intellij IDEA, Eclipse and Netbeans.
The plugin includes the possibility to convert any Java class to Kotlin, therefore the easiest way
is to generate the sample link:https://vaadin.com/maven[Java Vaadin Maven project] and
then convert the [filename]#MyUI# class to Kotlin, by pressing
kbd:[Ctrl+Alt+Shift+K]. The Kotlin plugin will convert the class and include Kotlin Maven plugin
to your [filename]#pom.xml#.

The link:https://github.com/mvysny/karibu-dsl[Karibu-DSL] library offers a more Kotlin-like
API for Vaadin. The library will allow you to create
your UI in a hierarchical way. For more details please see
link:https://kotlinlang.org/docs/reference/type-safe-builders.html[Kotlin Type-Safe Builders].
There is a link:https://github.com/mvysny/karibu-helloworld-application[Karibu Helloworld Application]
sample which demonstrates this technique. It is a standard Gradle project, thus you
only need to `git clone` the project and open it in your IDE. The hierarchical code looks as follows:

[source, kotlin]
----
@Theme("mytheme")
class MyUI : UI() {

    private lateinit var layout: VerticalLayout

    @Override
    override fun init(vaadinRequest: VaadinRequest) {
        layout = verticalLayout {
            val name = textField {
                caption = "Type your name here:"
            }
            button("Click Me", {
                println("Thanks ${name.value}, it works!")
                layout.label("Thanks ${name.value}, it works!")
            })
        }
    }
}
----

It is also possible to use Kotlin to access your database, allowing you to build full-blown
web applications. For details please see the
link:http://www.vaadinonkotlin.eu/[Vaadin-on-Kotlin] library. Just follow
the Getting Started tutorial there - the tutorial will guide you step-by-step.
n-hooks</option>
<option value='swistak'>swistak</option>
<option value='work'>work</option>
</select> <input type='submit' value='switch'/></form></td></tr>
<tr><td class='sub'>Mirror of redmine code source: https://github.com/redmine/redmine</td><td class='sub right'>www-data</td></tr></table>
<table class='tabs'><tr><td>
<a href='/redmine.git/?h=5.0.9'>summary</a><a href='/redmine.git/refs/?h=5.0.9'>refs</a><a href='/redmine.git/log/app/helpers/account_helper.rb?h=5.0.9'>log</a><a class='active' href='/redmine.git/tree/app/helpers/account_helper.rb?h=5.0.9'>tree</a><a href='/redmine.git/commit/app/helpers/account_helper.rb?h=5.0.9'>commit</a><a href='/redmine.git/diff/app/helpers/account_helper.rb?h=5.0.9'>diff</a><a href='/redmine.git/stats/app/helpers/account_helper.rb?h=5.0.9'>stats</a></td><td class='form'><form class='right' method='get' action='/redmine.git/log/app/helpers/account_helper.rb'>
<input type='hidden' name='h' value='5.0.9'/><select name='qt'>
<option value='grep'>log msg</option>
<option value='author'>author</option>
<option value='committer'>committer</option>
<option value='range'>range</option>
</select>
<input class='txt' type='search' size='10' name='q' value=''/>
<input type='submit' value='search'/>
</form>
</td></tr></table>
<div class='path'>path: <a href='/redmine.git/tree/?h=5.0.9'>root</a>/<a href='/redmine.git/tree/app?h=5.0.9'>app</a>/<a href='/redmine.git/tree/app/helpers?h=5.0.9'>helpers</a>/<a href='/redmine.git/tree/app/helpers/account_helper.rb?h=5.0.9'>account_helper.rb</a></div><div class='content'>blob: c58b263e019012492efb83767a4777f39f2c4c64 (<a href='/redmine.git/plain/app/helpers/account_helper.rb?h=5.0.9'>plain</a>)
<table summary='blob content' class='blob'>
<tr><td class='linenumbers'><pre><a id='n1' href='#n1'>1</a>
<a id='n2' href='#n2'>2</a>
<a id='n3' href='#n3'>3</a>
<a id='n4' href='#n4'>4</a>
<a id='n5' href='#n5'>5</a>
<a id='n6' href='#n6'>6</a>
<a id='n7' href='#n7'>7</a>
<a id='n8' href='#n8'>8</a>
<a id='n9' href='#n9'>9</a>
<a id='n10' href='#n10'>10</a>
<a id='n11' href='#n11'>11</a>
<a id='n12' href='#n12'>12</a>
<a id='n13' href='#n13'>13</a>
<a id='n14' href='#n14'>14</a>
<a id='n15' href='#n15'>15</a>
<a id='n16' href='#n16'>16</a>
<a id='n17' href='#n17'>17</a>
<a id='n18' href='#n18'>18</a>
<a id='n19' href='#n19'>19</a>
<a id='n20' href='#n20'>20</a>
<a id='n21' href='#n21'>21</a>
</pre></td>
<td class='lines'><pre><code>