How to Create Portlet Alternating Between Chart and HTML

The following example shows a dashboard logic which can switch to an HTML (e.g. such a nicely looking error message; here represented by the PFX logo) based on a condition (here represented by the 'decision').

def fields = [
  [name: "String value", type: FieldFormatType.TEXT],
  [name: "Integer value", type: FieldFormatType.INTEGER],
  [name: "Numeric value", type: FieldFormatType.NUMERIC],
  [name: "Percent value", type: FieldFormatType.PERCENT],
  [name: "Date value", type: FieldFormatType.DATE],

def m = api.newMatrix(fields.collect{it ->});
def rows = [];
def d = new Date();

for (int i=0; i< 500; i++) {
  rows << ["string text "+i, i, 0.11*i, 0.01*i, d-i];

fields.each {field ->
  m.setColumnFormat(, field.type);

rows.each {row ->
  m.addRow((0..row.size()-1).collectEntries{index ->
    [fields[index].name, row[index]]

///end matrix

def controller = api.newController()

controller.addHTML("<img src='' width=147 height=36/>")

return decision() ? m : controller;

boolean decision() {
  def m2 = new Date()
  return new BigDecimal(m2.getTime()).remainder( 2 ) != 0