- Kotlin 97.8%
- JavaScript 1.4%
- HTML 0.8%
kMultiPage - Server-Side framework for Kotlin
The main design goals of kMultiPage are:
- Allow programming simple application directly with Kotlin+HTML, without any JavaScript knowledge
- Use HTML directly to design pages, but make it easy to manipulate that HTML from Kotlin
- Process mostly on the server, but without requiring session-management or stateful components
- Hide the fact that the application is not a Single-Page-App from the user as much as possible
Start the complete documentation locally with the following command:
./gradlew :docs:run
Concept
Design your pages and components in pure HTML, e.g. my-page.html:
<html>
<body>
<h1 data-mpa-id="greeting"></h1>
<button data-mpa-on-click="helloClicked">Hello!</button>
</body>
</html>
You will use some special data- attributes to allow interaction between Kotlin and your HTML. Now, create a class to
handle this page:
@HtmlPage("my-page.html")
class MyPage: MyPageController() {
override fun build() {}
}
The base class MyPageController does not exist yet, so this class has compiler errors. But when you now run a full
build of your project, the kMultiPage compiler will create the base class for you, and from now on, you can interact with
the page. It even creates type-safe accessors for every element that has a data-mpa-id set, so you can access them from
your page class
But there's still a compiler error: The compiler created an abstract method vor handling button clicks on the server, and
you must implement that. Since the button has data-mpa-on-click="helloClicked", the handler method is called onHelloClicked:
@HtmlPage("my-page.html")
class MyPage: MyPageController() {
override fun build() {}
override fun onHelloClicked() {}
}
Now the class compiles, but it does not do anything yet... Let's add some functionality. We can use the greeting() accessor
that the compiler created for us to access the heading from the HTML file:
@HtmlPage("my-page.html")
class MyPage: MyPageController() {
override fun build() {
greeting().updateText { "Hello kMultiPage" }
}
override fun onHelloClicked() {
greeting().updateText { "You clicked the Hello-Button. Nice to meet you." }
}
}
License
Copyright 2025-2026 David Tanzer (business@davidtanzer.net)
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
See LICENSE.txt