liveBook · Manning

Checked template

As explained in Quarkus in Action

A checked template is a Qute template whose usage and parameter types are validated during the application build.

A checked template gives a Qute page a type-safe entry point. Declare a static class with `@CheckedTemplate`, then add a method returning `TemplateInstance` whose name matches the template file. Its parameters replace passing values through `data()`. Qute checks template usage during the build and reports invalid parameter references. section 6.2.3

To serve a reservation page:

  • Declare `index(LocalDate startDate, LocalDate endDate, String name)` in the annotated class for `index.html`. section 6.2.3
  • Call `Templates.index(...)` from the REST endpoint. Use `defaultName` on `@CheckedTemplate` if the file-naming convention differs; an underscored strategy maps `indexPage` to `index_page.html`. section 6.2.3
Listing 6.16 Building template instances with type safety
@CheckedTemplate
public static class Templates {
    public static native TemplateInstance index(
                    LocalDate startDate,
                    LocalDate endDate,
                    String name);

    public static native TemplateInstance listofreservations(
                    Collection<Reservation> reservations);

    public static native TemplateInstance availablecars(
                    Collection<Car> cars,
                    LocalDate startDate,
                    LocalDate endDate);
}

The declarations show typed entry points for the main page, reservations, and available cars. section 6.2.3

How Quarkus in Action covers it

How deep it goes
Explains annotation, method signatures, filename matching, and build-time checks without detailing Qute's checking internals.
Examples
Shows typed methods for an index page, reservation list, and available-car list.
What it assumes
Assumes familiarity with Java methods and REST endpoints while introducing the checked-template declaration.
What you can do after
Build it from scratch: declare checked template methods and call them from REST endpoints.
How it connects
Connects Qute templates to REST endpoints, template instances, Java parameter types, and HTMX-driven pages.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Quarkus in Action. The section links point to the parts of the book it draws on.