This tutorial demonstrates the rendering of raw HTML for a WoOF web application.
The example used in this tutorial is the following simple page:
The HTML for the page is as follows:
<html> <body> ${rawHtml} </body> </html>
This is similar HTML to previous tutorials.
The logic for the rendering the page is the following POJO (plain old java object).
public class TemplateLogic { /** * Able to use <code>this</code> as bean for populating. * * @return {@link TemplateLogic} to provide properties. */ public TemplateLogic getTemplateData() { return this; } /** * Provides the raw HTML to render. It is not escaped due to the * {@link NotEscaped} annotation. * * @return Raw HTML to render. */ @NotEscaped public String getRawHtml() { return "<p style=\"color: blue\">" + "<img src=\"./images/OfficeFloorLogo.png\" />" + " Web on OfficeFloor (WoOF)</p>"; } }
To generate HTML for the page and not have it automatically escaped by WoOF, annotate the property method with @NotEscaped. This informs WoOF to not escape the property value and render it as is.
This is a very simple example. More complex use of this would be presentation beans that provide dynamic generation of HTML. Please however consider using the ${bean ... $} tag first before generating raw HTML, as the tag will provide the necessary functionality in the majority of cases.
The next tutorial looks at serving AJAX requests.