Skip to main content

@HtmlDocConfig Annotation

The @HtmlDocConfig annotation is used to customize the HTML view of POJOs serialized by HtmlDocSerializer.

HtmlDocConfigasideasideFloatfooterheadheadernavnavlinksnoResultsMessagenowraprankscriptstylestylesheettemplatewidgets

It's used in the following locations:

RestRestOp

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​