@HtmlDocConfig Annotation
The @HtmlDocConfig annotation is used to customize the HTML view of POJOs serialized by HtmlDocSerializer.
It's used in the following locations:
For example, the following shows setting the title on a page:
@Rest
@HtmlDocConfig(
title="My Resource Page"
)
The purpose of this annotation is to populate the HTML document view which by default consists of the following structure:
<html>
<head>
<style type='text/css'>
CSS styles and links to stylesheets
</style>
</head>
<body>
<header>
Page header
</header>
<nav>
Navigation links
</nav>
<aside>
Side-bar text
</aside>
<article>
Contents of serialized object
</article>
<footer>
Footer message
</footer>
</body>
</html>
The outline above is controlled by the HtmlDocTemplate interface which can be overridden via the @HtmlDocConfig(template) annotation.
Here's a minimal, self-contained example of the @HtmlDocConfig annotation
in use. (The HelloWorldResource class it's modeled after was part of the now-removed juneau-examples-rest module; this snippet is
illustrative and not tied to a currently-shipping class.)
// Sample REST resource that prints out a simple "Hello world!" message.
@Rest(
path="/helloWorld",
title="Hello World",
description="An example of the simplest-possible resource"
)
@HtmlDocConfig(
navlinks={
"up: request:/..",
"options: servlet:/?method=OPTIONS"
},
aside={
"<div style='max-width:400px' class='text'>",
" <p>This page shows a resource that simply response with a 'Hello world!' message</p>",
" <p>The POJO serialized is a simple String.</p>",
"</div>"
}
)
public class HelloWorldResource extends BasicRestServlet {
@RestGet(path="/*", summary="Responds with \"Hello world!\"")
public String sayHello() {
return "Hello world!";
}
}
SVL variables can be used in any of these annotations:
@Rest(
path="/helloWorld",
// Register a config file.
config="MyConfig.cfg"
)
@HtmlDocConfig(
navlinks={
"up: request:/..",
"options: servlet:/?method=OPTIONS",
// Add a nav link to view the source code for this class.
"source: ${C:Source/gitHub}/org/apache/juneau/petstore/jetty/${R:servletClassSimple}.java"
},
aside={
// Localize our messages.
"<div style='max-width:400px' class='text'>",
" <p>${L:localizedMessage1}</p>",
" <p>${L:localizedMessage2}</p>",
"</div>"
}
)
public class HelloWorldResource extends BasicRestServlet {...}
In This Section
3.3.29.1. User Interfaces (UI) vs. Developer Interfaces (DI)
An important distinction needs to be made about the HTML representations produced by the REST API.
3.3.29.2. Widgets
The Widget class allows you to add arbitrary HTML, CSS, and
3.3.29.3. Predefined Widgets
The org.apache.juneau.rest.server.widget package contains predefined reusable widgets.
3.3.29.4. UI Customization
The HTML views of POJOs can somewhat be considered a rudimentary User Interface.
3.3.29.5. Stylesheets
Every page served by a BasicRestServlet is styled by one stylesheet. These shots are the petstore's bean-description