The {@link oaj.examples.rest.HtmlBeansResource} class shows how {@link oaj.dto.html5 HTML5 beans} can be
used to generate arbitrary HTML on REST endpoints.
table
The {@link oaj.examples.rest.HtmlBeansResource#aTable() aTable()} method shows an example
of rendering an HTML table.
import static org.apache.juneau.dto.html5.HtmlBuilder.*;
@RestGet("/table")
@HtmlDocConfig(
aside={
"<div class='text'>",
" <p>Example of serialized table.</p>",
"</div>"
}
)
public Table aTable() {
return table(
tr(
th("c1"),
th("c2")
),
tr(
td("v1"),
td("v2")
)
);
}
div
The {@link oaj.examples.rest.HtmlBeansResource#aDiv() aDiv()} method shows an example
of rendering a div tag with mixed content.
import static org.apache.juneau.dto.html5.HtmlBuilder.*;
@RestGet("/div")
@HtmlDocConfig(
aside={
"<div class='text'>",
" <p>Example of serialized div tag.</p>",
"</div>"
}
)
public HtmlElement aDiv() {
return div()
.children(
p("Juneau supports ", b(i("mixed")), " content!")
)
.onmouseover("alert(\"boo!\");");
}
form
The {@link oaj.examples.rest.HtmlBeansResource#aForm() aForm()} method shows an example
of rendering an HTML form.
import static org.apache.juneau.dto.html5.HtmlBuilder.*;
@RestGet("/form")
@HtmlDocConfig(
aside={
"<div class='text'>",
" <p>Example of serialized HTML form.</p>",
"</div>"
}
)
public Form aForm() {
return form().action("/submit").method("POST")
.children(
"Position (1-10000): ", input("number").name("pos").value(1), br(),
"Limit (1-10000): ", input("number").name("limit").value(100), br(),
button("submit", "Submit"),
button("reset", "Reset")
);
}