Predefined Widgets
The org.apache.juneau.rest.server.widget package contains predefined reusable widgets.
These are $W{...} HTML widgets. For the typed ModalDef, FormDef, CalendarDef and stats beans in
juneau-console-widgets, see Declarative Widgets.
MenuItemWidget
MenuItemWidget is an abstract class for rendering menu
items with drop-downs.
It defines some simple CSS and Javascript for enabling drop-down menus in the nav section of the page (although nothing
keeps you from using it in an arbitrary location in the page).
The script specifies a menuClick(element) function that toggles the visibility of the next sibling of the element.
Subclasses implement the following methods:
For example, to render a link that brings up a simple dialog in a div tag:
@Override
public String getLabel(RestRequest req, RestResponse res) {
return "my-menu-item";
}
@Override
public Object getContent(RestRequest req, RestResponse res) {
return HtmlBuilder.div("Surprise!").style("color:red");
}
The HTML content returned by the getHtml(RestRequest,RestResponse) method is added where the $W{...} is referenced in the page.
ContentTypeMenuItem
ContentTypeMenuItem is a predefined Widget that
returns back a list of hyperlinks for rendering the contents of a page in a variety of content types.
The variable it resolves is $W{ContentTypeMenuItem}.
An example of this widget can be found in RootResources (juneau-petstore-jetty), which provides a drop-down menu item for
rendering the current page's contents in a variety of content types:
@Rest(
title="Juneau Petstore (Jetty)",
description="Apache Juneau petstore sample application running under Jetty/Microservice.",
children={...}
)
@HtmlDocConfig(
widgets={
ContentTypeMenuItem.class
},
navlinks={
"api: servlet:/api",
"stats: servlet:/stats",
"$W{ContentTypeMenuItem}",
"source: $C{Source/gitHub}/org/apache/juneau/petstore/jetty/RootResources.java"
}
)
public class RootResources extends BasicRestServletGroup {...}
It renders the following popup-box:

QueryMenuItem
QueryMenuItem is a predefined Widget that returns a
menu-item drop-down form for entering search/view/sort arguments.
The variable it resolves is $W{QueryMenuItem}.
This widget is designed to be used in conjunction with the Queryable converter, although implementations can process the query parameters themselves by taking a BeanQueryRequest method argument (bound from the search, view, sort, position and limit request parameters) and running a BeanQuery session over their data.
Neither of the currently-shipping petstore resources pairs this widget with the Queryable converter, so the following is a
self-contained, minimal illustrative example rather than a citation of an existing class:
@Rest
public class MyResource extends BasicRestServlet {
@RestGet(
path="/",
converters=Queryable.class
)
@HtmlDocConfig(
widgets={
QueryMenuItem.class,
},
navlinks={
"up: request:/..",
"options: ?method=OPTIONS",
"$W{QueryMenuItem}",
"$W{ContentTypeMenuItem}"
}
)
public Collection<MyBean> getBeans() {
...
}
}
It renders the following popup-box:

Tooltips are provided by hovering over the field names.

When submitted, the form submits a GET request against the current URI with the BeanQuery query parameters
(e.g. ?search=column1=$prefix(Foo)&view=column1,column2&sort=column1,column2:desc&position=100&limit=100).
The Queryable class knows how to perform these filters
against collections of POJOs. The tooltips describe the BeanQuery operators ($eq, $contains, $gt, $between, $and/$or/$not, ...); see the BeanQuery page for the full grammar. The old "Ignore-case" checkbox is gone: case sensitivity is a property of each operator.
PoweredByJuneau
PoweredByJuneau is a predefined Widget that places a
powered-by-Juneau message on a page.
The variable it resolves is $W{PoweredByJuneau}.
It produces a simple Apache Juneau icon floating on the right.
Typically it's used in the footer of the page, as shown in this minimal example:
@Rest(path="/myResource")
@HtmlDocConfig(
widgets={
PoweredByJuneau.class
},
footer="$W{PoweredByJuneau}"
)
public class MyResource extends BasicRestServlet {...}
It renders the following image:
PoweredByApache
PoweredByApache is a predefined Widget that places a
powered-by-Apache message on a page.
The variable it resolves is $W{PoweredByApache}.
It produces a simple Apache icon floating on the right, hyperlinked to http://apache.org.
Typically it's used in the footer of the page, as shown in this minimal example:
@Rest(path="/myResource")
@HtmlDocConfig(
widgets={
PoweredByApache.class
},
footer="$W{PoweredByApache}"
)
public class MyResource extends BasicRestServlet {...}
Tooltip
Tooltip is a predefined template for adding tooltips to HTML5 bean constructs, typically in menu item widgets.
The following examples shows how tooltips can be added to a menu item widget.
public class MyFormMenuItem extends MenuItemWidget {
@Override
public String getLabel(RestRequest req, RestResponse res) {
return "myform";
}
@Override
public Object getContent(RestRequest req, RestResponse res) {
return div(
form().id("form").action("servlet:/form").method("post").children(
table(
tr(
th("Field 1:"),
td(input().name("field1").type("text")),
td(new Tooltip("(?)", "This is field #1!", br(), "(e.g. '", code("Foo"), "')"))
),
tr(
th("Field 2:"),
td(input().name("field2").type("text")),
td(new Tooltip("(?)", "This is field #2!", br(), "(e.g. '", code("Bar"), "')"))
)
)
)
);
}
}