mvysny/vaadin-on-kotlin
À propos
Writing full-stack statically-typed web apps on JVM at its simplest
Développement web et applicatifProgression mesurée des étoiles
- in 24h
- 0
- in 7 days
- 0
- in 15 days
- 0
- in 1 month
- Historique en cours
Variations nettes sur des périodes qui se chevauchent, pas des totaux quotidiens. Les mesures absentes restent vides. Les étoiles indiquent l’intérêt, pas la qualité.
README.md
OriginalWelcome to Vaadin-on-Kotlin
vok-restmoved from Javalin 5 to Javalin 7. Javalin 7 registers routes only insideJavalin.create { }, soJavalin.crud2(...)becameconfig.routes.crud2(...), andJavalin.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
Install JDK 21 (required by Vaadin 25) and a git client if you don't already have them.
Clone the example app and run it:
git clone https://github.com/mvysny/vaadin-on-kotlin cd vaadin-on-kotlin ./gradlew vok-example-crud:runVisit http://localhost:8080. The CRUD demo backs a Vaadin Grid by a ktorm-vaadin
EntityDataProvider, with filter components attached to the grid header.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 wiresActiveKtorm.database), thetoId(idColumn)Binder helper, and a reified-genericenumFilterField<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 behindallowModification. - 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
- Vaadin troubleshooting
- ktorm docs
- ktorm-vaadin
- beverage-buddy-ktorm — canonical end-to-end example
License
Licensed under the MIT License.
Copyright (c) 2017-2026 Martin Vysny.
Explorer des projets similaires
Chargement…