FormFunction { @FunctionMeta(description = "Show radio from an object's properties in a form", example = "${w:showRadio('groupBy', groupBy, payload.groupBy, 'name', 'description')}") public static String showRadio(String inputName, Object item, Object selected, String valueName, String textName) { StringBuilder sb = new StringBuilder(256); Object value = getPropertyValue(item, valueName); Object text = getPropertyValue(item, textName); String id = inputName + '-' + value; sb.append("<input type=\"radio\" name=\"").append(inputName).append("\" value=\"").append(value).append("\" id=\"") .append(id).append("\""); sb.append(getSelectedOrChecked(selected, value, false)); sb.append("><label for=\"").append(id).append("\">").append(text).append("</label>"); 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 testRadio() { String result = FormFunction.showRadio("obj", getObjects().get(1), "2", "value", "name"); String expected = "<input type=\"radio\" name=\"obj\" value=\"2\" id=\"obj-2\" checked><label for=\"obj-2\">Second</label>"; Assert.assertEquals(expected, result); }