Skip to content

UI & UISpec Annotations

public @interface UI {
String value(); // required: URL path
String indexHtmlPath() default "/static/_index.html";
String frontendComponentPath() default "/assets/mateu.js";
}

The foundational annotation of the Mateu framework. Registers a Java class as a UI endpoint accessible at the given URL path.

AttributeTypeDefaultDescription
valueStringURL path where this UI is served (e.g. /orders)
indexHtmlPathString/static/_index.htmlPath to the HTML shell page
frontendComponentPathString/assets/mateu.jsPath to the frontend JS component

How it works:

  1. Mateu’s annotation processor scans for @UI at startup
  2. Registers the class as a handler for the given path
  3. When a request arrives, instantiates the class and generates the UIDL (UI Definition Language) response
  4. The frontend renders the UIDL as an interactive UI

Example:

@UI("/orders")
public class Orders extends AutoCrud<Order> {
@Override
public CrudRepository<Order> repository() {
return new OrderRepository();
}
}

@Repeatable(Scripts.class)
public @interface Script {
String src();
String type() default "";
boolean crossorigin() default false;
boolean defer() default false;
boolean async() default false;
}

Injects a <script> tag into the <head> of the generated HTML page. Can be applied multiple times to the same class.

AttributeTypeDefaultDescription
srcStringURL of the script file
typeString""Value for the type attribute (e.g. "module"). Omitted when empty
crossoriginbooleanfalseAdds the crossorigin attribute
deferbooleanfalseAdds the defer attribute
asyncbooleanfalseAdds the async attribute
@UI("/dashboard")
@Script(src = "/assets/charts.js", type = "module")
@Script(src = "/assets/analytics.js", defer = true)
public class Dashboard { ... }

The generated HTML will contain, before </head>:

<script type="module" src="/assets/charts.js"></script>
<script src="/assets/analytics.js" defer></script>

@Repeatable(Links.class)
public @interface Link {
String rel();
String href();
String type() default "";
String as() default "";
boolean crossorigin() default false;
}

Injects a <link> tag into the <head> of the generated HTML page. Typical uses include stylesheets, preloads, and web fonts. Can be applied multiple times.

AttributeTypeDefaultDescription
relStringValue for the rel attribute (e.g. "stylesheet", "preload")
hrefStringURL of the linked resource
typeString""Value for the type attribute. Omitted when empty
asString""Value for the as attribute (used with rel="preload"). Omitted when empty
crossoriginbooleanfalseAdds the crossorigin attribute
@UI("/dashboard")
@Link(rel = "stylesheet", href = "/assets/custom-theme.css")
@Link(rel = "preload", href = "/assets/fonts/inter.woff2", as = "font", crossorigin = true)
public class Dashboard { ... }

The generated HTML will contain, before </head>:

<link rel="stylesheet" href="/assets/custom-theme.css">
<link rel="preload" href="/assets/fonts/inter.woff2" as="font" crossorigin>

@Repeatable(Metas.class)
public @interface Meta {
String name() default "";
String content();
String httpEquiv() default "";
String charset() default "";
}

Injects a <meta> tag into the <head> of the generated HTML page. Can be applied multiple times.

AttributeTypeDefaultDescription
contentStringValue for the content attribute
nameString""Value for the name attribute (e.g. "description", "viewport"). Omitted when empty
httpEquivString""Value for the http-equiv attribute. Omitted when empty
charsetString""Value for the charset attribute. Omitted when empty
@UI("/dashboard")
@Meta(name = "description", content = "Sales dashboard for the admin panel")
@Meta(name = "viewport", content = "width=device-width, initial-scale=1")
public class Dashboard { ... }

The generated HTML will contain, before </head>:

<meta name="description" content="Sales dashboard for the admin panel">
<meta name="viewport" content="width=device-width, initial-scale=1">

The three annotations can be combined freely on the same @UI class:

@UI("/store")
@Meta(name = "description", content = "Online store powered by Mateu")
@Link(rel = "stylesheet", href = "/assets/store-theme.css")
@Link(rel = "preload", href = "/assets/fonts/brand.woff2", as = "font", crossorigin = true)
@Script(src = "https://cdn.example.com/analytics.js", defer = true)
public class Store extends AutoCrud<Product> { ... }

public @interface UISpec {
String value(); // path to YAML UI specification file
}

Alternative to code-based UI definition. Points to a YAML file that describes the UI structure declaratively without Java annotations.

Used when:

  • The UI is defined by a non-Java team
  • The UI structure changes frequently without code changes
  • Integrating with external tooling that generates YAML

Cross-reference: see the YAML UI Definition guide for the full YAML format.