In some cases you may want to return an HTML string from your formatter. This may be useful to customize the displayed text (eg. with embedded bold/italic tags), or present a link. This can be achieved by overriding the following method:
publicbooleanreturnsHtml() { return false; }
By default, this method returns false, indicating that any HTML entities in the formatted values should be escaped when outputting to HTML. By overriding this to return true, Yellowfin will not do any HTML escaping. An example of a formatter that includes HTML output is provided below:
public boolean returnsHtml() { return true; } public String render(Object value, int renderType) throws Exception { if (value == null) return null; if (renderType == RENDER_LINK) { return value.toString(); } else if (renderType == RENDER_HTML) { return "<b>" + value.toString() + "</b>"; } else { // rendering to non-html output return value.toString(); } }
Additional Examples
Click here for a full example of a custom formatter that takes a numeric value, and formats it as a currency value.
Previous topic: Formatter implementation
Next topic: Formatter packaging