FormFunction { @FunctionMeta(description = "Show multiple radios from a list or array object's properties in a form", example = "${w:showRadios('groupBy', groupBys, payload.groupBy, 'name', 'description')}") public static String showRadios(String inputName, Object items, Object selected, String valueName, String textName) { StringBuilder sb = new StringBuilder(); if (items instanceof Object[]) { for (Object item : (Object[]) items) { sb.append(showRadio(inputName, item, selected, valueName, textName)); sb.append("\r\n"); } } else if (items instanceof List) { for (Object item : (List<?>) items) { sb.append(showRadio(inputName, item, selected, valueName, textName)); sb.append("\r\n"); } } else if (items != null) { throw new RuntimeException("Object[] or List expected, but was: " + items.getClass()); } return sb.toString(); }  @FunctionMeta(description = "Show checkbox from an object's properties in a form", example = "${w:showCheckbox('groupBy', groupBy, payload.groupBy, 'name', 'description')}") static String showCheckbox(String inputName, Object item, Object selected, String valueName, String textName); @FunctionMeta(description = "Show multiple checkboxes from a list or array object's properties in a form", example = "${w:showCheckboxes('groupBy', groupBys, payload.groupBy, 'name', 'description')}") static String showCheckboxes(String inputName, Object items, Object selected, String valueName, String textName); @FunctionMeta(description = "Show select option from an object's properties in a form", example = "${w:showOption(groupBy, payload.groupBy, 'name', 'description')}") static String showOption(Object item, Object selected, String valueName, String textName); @FunctionMeta(description = "Show multiple select options from a list or array object's properties in a form", example = "${w:showOptions(groupBys, payload.groupBy, 'name', 'description')}") static String showOptions(Object items, Object selected, String valueName, String textName); @FunctionMeta(description = "Show radio from an object's properties in a form", example = "${w:showRadio('groupBy', groupBy, payload.groupBy, 'name', 'description')}") static String showRadio(String inputName, Object item, Object selected, String valueName, String textName); @FunctionMeta(description = "Show multiple radios from a list or array object's properties in a form", example = "${w:showRadios('groupBy', groupBys, payload.groupBy, 'name', 'description')}") static String showRadios(String inputName, Object items, Object selected, String valueName, String textName); @FunctionMeta(description = "Show selected result of checkbox, radio or option from an object's properties in a form", example = "${w:showResult(groupBys, payload.groupBy, 'name', 'description')}") static Object showResult(Object items, Object selected, String valueName, String textName);  }
@Test public void testRadios() { String result = FormFunction.showRadios("obj", getObjects(), "2", "value", "name"); String expected = "<input type=\"radio\" name=\"obj\" value=\"1\" id=\"obj-1\"><label for=\"obj-1\">First</label>\r\n" + "<input type=\"radio\" name=\"obj\" value=\"2\" id=\"obj-2\" checked><label for=\"obj-2\">Second</label>\r\n" + "<input type=\"radio\" name=\"obj\" value=\"3\" id=\"obj-3\"><label for=\"obj-3\">Third</label>\r\n"; Assert.assertEquals(expected, result); }