Skip to content

Getting started

yassinezerguine08 edited this page Oct 30, 2026 · 3 revisions

Getting started

This page builds the smallest Oriel application: one page with a form, one action that answers it, and the window around them. The calls in main are the ones every Oriel application makes.

1. Add Oriel to the build

Oriel is released from tags and fetched through JitPack, which builds the tag it is asked for, so no token is needed. oriel-window brings oriel-server with it. Oriel logs through SLF4J, so add a binding such as Logback to see what it says.

<repositories>
	<repository>
		<id>jitpack</id>
		<url>https://jitpack.io</url>
	</repository>
</repositories>

<dependency>
	<groupId>com.github.unigrid-project.oriel</groupId>
	<artifactId>oriel-window</artifactId>
	<version>0.0.1</version>
</dependency>
<dependency>
	<groupId>ch.qos.logback</groupId>
	<artifactId>logback-classic</artifactId>
	<version>1.5.12</version>
	<scope>runtime</scope>
</dependency>

The version is the tag's name, 0.0.1; 0.0.1 is also tagged v0.0.1, which still works but is not a version Maven can order. To work against Oriel's latest code instead, build it with ./mvnw install: that puts it in your local Maven repository as org.unigrid.oriel, at the version in Oriel's pom, such as 0.0.2-SNAPSHOT.

2. A view and its template

A view is any object that implements View and names its template. A record works well, because the template reads its accessors directly.

public record IndexView(GreetingView greeting) implements View {
	@Override
	public String template() {
		return "index";
	}
}

public record GreetingView(String name) implements View {
	@Override
	public String template() {
		return "index :: greeting";
	}
}

Templates live under templates/ on the classpath, so "index" is src/main/resources/templates/index.html and "index :: greeting" is the block of that file marked th:fragment="greeting". The template sees the view as view.

<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
	<head>
		<meta charset="utf-8">
		<title>Hello</title>
		<script src="/oriel/htmx.min.js" defer></script>
		<script src="/oriel/window.js" defer></script>
		<script src="/oriel/failure.js" defer></script>
	</head>
	<body data-failure-message="That did not work. The reason is in the log.">
		<!-- The frame has no title bar of its own, so the page draws one. -->
		<header data-drag>
			<span>Hello</span>
			<button type="button" data-window="minimise" aria-label="Minimise">–</button>
			<button type="button" data-window="maximise" aria-label="Maximise">□</button>
			<button type="button" data-window="close" aria-label="Close">✕</button>
		</header>

		<main data-failure-host>
			<form hx-post="/action/greet" hx-target="#greeting" hx-swap="outerHTML">
				<input name="name" placeholder="Your name">
				<button type="submit">Greet</button>
			</form>

			<th:block th:with="view=${view.greeting()}">
				<p th:fragment="greeting" id="greeting" th:text="'Hello, ' + ${view.name()} + '!'">Hello!</p>
			</th:block>
		</main>
	</body>
</html>

3. An action

An action is a method annotated with @Action. The page reaches it at /action/<name>. It takes nothing or a Form and returns nothing or a view, which Oriel renders and sends back for htmx to swap in.

public class Greeter {
	/** What the window opens on. */
	public IndexView start() {
		return new IndexView(new GreetingView("stranger"));
	}

	@Action("greet")
	public GreetingView onGreet(final Form form) {
		return new GreetingView(form.has("name") ? form.get("name") : "stranger");
	}
}

4. The window

main serves the page on a local port and opens the window on it. The first address carries a one-time session token, which Oriel swaps for a cookie straight away; see The server and its security.

public final class Hello {
	private Hello() {
	}

	public static void main(final String[] args) throws Exception {
		final Application application = new Application(AppId.of("hello"), "Hello", List.of(),
			new Dimension(800, 600), new Dimension(480, 360)
		);
		final LaunchOptions options = LaunchOptions.of(args);
		final BrowserWindow window = new BrowserWindow(application, options.windowSystem());
		final SessionToken token = SessionToken.random();
		final Greeter greeter = new Greeter();
		final UiServer server = new UiServer(Routes.create(application.id(), new Templates(false), token,
			window.control(), Actions.of(greeter), greeter::start
		));
		final URI uri = server.start();

		window.open(uri.resolve("/?" + SessionToken.PARAMETER + "=" + token.value()));
	}
}
  • Application names the app and gives its icons and sizes; see The window. An empty icon list leaves the desktop's own icon.
  • AppId is the short id Oriel names the app's cookie, engine folder and engine property after.
  • LaunchOptions takes Oriel's one command-line option, --window-system, and hands the rest back in options.remaining() for the application to read.
  • Actions.of(greeter) binds the actions of plain objects. With CDI, Actions.discovered(…) finds them instead; see Actions.
  • new Templates(false) reads the templates afresh on every request, which suits development. Pass true to cache them.

5. Run it

Run main as any Java program. The first start without an installer downloads the browser engine into ~/.hello/jcef, which takes a while once; later starts reuse it. On macOS, Chromium needs some JVM options; see Building and packaging.

You now have a window showing your own page. From here:

Clone this wiki locally