Skip to content
プロジェクト

mvysny/vaadin-on-kotlin

GitHubで見る

概要

Writing full-stack statically-typed web apps on JVM at its simplest

Web・アプリ開発

この数値の測り方

計測したスター増加

24時間
0
7日間
0
15日間
0
1か月
履歴を収集中

期間ごとの純増数です。期間は重複しており、日別の値ではありません。未計測の値は空欄です。スター数は注目度の指標であり、品質の保証ではありません。

Powered By Vaadin on Kotlin GitHub tag Maven Central Build Status

Welcome to Vaadin-on-Kotlin

vok-rest moved from Javalin 5 to Javalin 7. Javalin 7 registers routes only inside Javalin.create { }, so Javalin.crud2(...) became config.routes.crud2(...), and Javalin.createStandalone() is gone. See vok-rest for the new servlet shape.

0.19 is a breaking release. The persistence layer moved from vok-orm (jdbi-orm) to ktorm + ktorm-vaadin. The published REST wire format also simplified to eq-only filters with ?offset / ?limit / ?sort=col:asc,col2:desc. If you're upgrading from 0.18.x, check the per-module READMEs for the new shapes and see vok-example-crud for an end-to-end example.

Vaadin-on-Kotlin is a web-application framework for database-backed apps in Kotlin. It enforces neither MVC, dependency injection nor service-oriented architecture, and uses neither Spring nor JavaEE. The view layer is Vaadin's component-oriented model; persistence is ktorm — typed-SQL DSL, entity sequences, no XML — wrapped by ktorm-vaadin. VoK owns the glue between the two plus REST server and client support; depend on vok-framework alone and bring your own persistence.

Documentation lives at www.vaadinonkotlin.eu. The Accessing SQL Databases guide and the per-module READMEs are current; the tutorial and NoSQL/REST data sources page still describe pre-0.19 idioms and are awaiting a rewrite — refer to vok-example-crud for current patterns.

Getting started

  1. Install JDK 21 (required by Vaadin 25) and a git client if you don't already have them.

  2. Clone the example app and run it:

    git clone https://github.com/mvysny/vaadin-on-kotlin
    cd vaadin-on-kotlin
    ./gradlew vok-example-crud:run
    
  3. Visit http://localhost:8080. The CRUD demo backs a Vaadin Grid by a ktorm-vaadin EntityDataProvider, with filter components attached to the grid header.

  4. See vok-example-crud for the demo source. For the canonical end-to-end ktorm-vaadin sample, see beverage-buddy-ktorm.

Modules

  • vok-framework — VoK runtime core: bootstrap, Session, Cookies, async executor, i18n. No DB dependency. Always pulled in transitively.
  • vok-framework-vokdb — Vaadin + SQL via ktorm + ktorm-vaadin. Provides VaadinOnKotlin.dataSource (which also wires ActiveKtorm.database), the toId(idColumn) Binder helper, and a reified-generic enumFilterField<E>() factory.
  • vok-rest — REST server support. Javalin 7 + Gson. Exposes ktorm tables via Table<E>.getCrudHandler() — GET list/one plus POST/PATCH/DELETE, the latter three behind allowModification.
  • vok-rest-client — REST client helpers built on the JDK HttpClient. ORM-agnostic.
  • vok-example-crud — runnable demo and integration-test harness.

Code examples

Define a ktorm entity + table

interface Person : ActiveEntity<Person> {
    var id: Long?
    @get:NotNull @get:Size(min = 1, max = 200) var name: String?
    @get:NotNull @get:Min(15) @get:Max(100)   var age: Int?
    var dateOfBirth: LocalDate?
    override val table: Table<Person> get() = Persons
    companion object : Entity.Factory<Person>()
}

object Persons : Table<Person>("Person") {
    val id = long("id").primaryKey().bindTo { it.id }
    val name = varchar("name").bindTo { it.name }
    val age = int("age").bindTo { it.age }
    val dateOfBirth = date("dateOfBirth").bindTo { it.dateOfBirth }
}

Bootstrap

@WebListener
class Bootstrap : ServletContextListener {
    override fun contextInitialized(sce: ServletContextEvent?) {
        VaadinOnKotlin.dataSource = HikariDataSource(hikariConfig)  // wires ActiveKtorm.database too
        VaadinOnKotlin.init()
        Flyway.configure().dataSource(VaadinOnKotlin.dataSource).load().migrate()
    }
    override fun contextDestroyed(sce: ServletContextEvent?) {
        VaadinOnKotlin.destroy()
    }
}

Save / query

val p = Person { name = "Leto"; age = 45 }.create()           // insert
val one = db { database.sequenceOf(Persons).find { it.id eq p.id!! } }
val all = db { database.sequenceOf(Persons).toList() }

Grid with ktorm-vaadin DataProvider + filters

private val nameFilter = FilterTextField()
private val ageFilter  = NumberRangePopup()
private val dataProvider = Persons.dataProvider

personGrid = grid<Person>(dataProvider) {
    appendHeaderRow()
    val filterBar = appendHeaderRow()
    columnFor(Person::name, key = Persons.name.e.key) {
        filterBar.getCell(this).component = nameFilter
        nameFilter.addValueChangeListener { updateFilter() }
    }
    columnFor(Person::age, key = Persons.age.e.key) {
        filterBar.getCell(this).component = ageFilter
        ageFilter.addValueChangeListener { updateFilter() }
    }
}

private fun updateFilter() {
    val conditions = mutableListOf<ColumnDeclaring<Boolean>?>()
    if (nameFilter.value.isNotBlank()) conditions += Persons.name.ilike("${nameFilter.value.trim()}%")
    conditions += Persons.age.between(ageFilter.value.asIntegerInterval())
    dataProvider.setFilter(conditions.and())
}

UI DSL

verticalLayout {
    formLayout {
        textField("Name:") { focus() }
        textField("Age:")
    }
    horizontalLayout {
        button("Save") {
            onClick { okPressed() }
            setPrimary()
        }
    }
}

REST server (vok-rest)

@WebServlet(urlPatterns = ["/rest/*"])
class JavalinRestServlet : HttpServlet() {
    private val javalin = Javalin.create {
        it.startup.startupWatcherEnabled = false
        it.gsonMapper(VokRest.gson)
        it.routes.crud2("/rest/person", Persons.getCrudHandler(allowModification = true))
    }.javalinServlet()
    override fun service(req: HttpServletRequest, resp: HttpServletResponse) { javalin.service(req, resp) }
}

Exposes GET /rest/person?name=Leto&offset=0&limit=20&sort=age:desc&count=true and so on. See vok-rest for the full wire format.

Contributing

Bug reports: VoK issue tracker.

Further links

License

Licensed under the MIT License.

Copyright (c) 2017-2026 Martin Vysny.

関連プロジェクトを探す

読み込み中…