@Override protected void registerWidgets(FormEntryContext context) { for (TextFieldWidget textWidget : widgetMap.values()) { context.registerWidget(textWidget); } }
@Override protected void registerWidgets(FormEntryContext context) { for (String key : widgetMap.keySet()) { context.registerWidget(widgetMap.get(key)); } } }
/** * Registers an error widget within the Context * * @param widget: the widget to associate this error widget with * @param errorWidget: the error widget to register * @return the field id used to identify this widget in the HTML Form */ public String registerErrorWidget(Widget widget, ErrorWidget errorWidget) { String errorWidgetId; if (!fieldNames.containsKey(errorWidget)) { errorWidgetId = registerWidget(errorWidget); } else { errorWidgetId = getFieldName(errorWidget); } errorWidgets.put(widget, errorWidget); return errorWidgetId; }
private void createWidgets(FormEntryContext context, Widget fieldWidget, ErrorWidget errorWidget, Object initialValue) { context.registerWidget(fieldWidget); if (errorWidget != null) { context.registerErrorWidget(fieldWidget, errorWidget); } if (initialValue != null && StringUtils.hasText(initialValue.toString())) { fieldWidget.setInitialValue(initialValue); } }
static void setupDropdownWidget(FormEntryContext context, DropdownWidget widget, List<Option> options) { if (context.getMode() != Mode.VIEW) { widget.setOptions(options); if (!options.isEmpty()) { widget.setInitialValue(options.get(0).getValue()); } } else { widget.setOptions(new ArrayList<Option>()); } context.registerWidget(widget); }
private void createDurationWidget(FormEntryContext context) { durationWidget = new NumberFieldWidget(0d, 9999999d, true); context.registerWidget(durationWidget); durationErrorWidget = new ErrorWidget(); context.registerErrorWidget(durationWidget, durationErrorWidget); }
private void createNumRefillsWidget(FormEntryContext context){ numRefillsWidget = new NumberFieldWidget(0d, 9999999d, false); context.registerWidget(numRefillsWidget); numRefillsErrorWidget = new ErrorWidget(); context.registerErrorWidget(numRefillsWidget, numRefillsErrorWidget); }
private void createQuantityWidget(FormEntryContext context) { quantityWidget = new NumberFieldWidget(0d, 9999999d, true); context.registerWidget(quantityWidget); quantityErrorWidget = new ErrorWidget(); context.registerErrorWidget(quantityWidget, quantityErrorWidget); }
dateWidget.setInitialValue(existingObsGroup != null ? existingObsGroup.getObsDatetime() : null); context.registerWidget(dateWidget); context.registerErrorWidget(dateWidget, errorWidget); } else { checkboxWidget.setInitialValue(existingObsGroup != null ? Boolean.TRUE : null); context.registerWidget(checkboxWidget); context.registerErrorWidget(checkboxWidget, errorWidget);
/** * Be aware it's called by the constructor. * * @param context * @param mss */ protected void createFrequencyWidget(FormEntryContext context, MessageSourceService mss) { frequencyWidget = new DropdownWidget(); frequencyErrorWidget = new ErrorWidget(); // fill frequency drop down lists (ENTER, EDIT) List<Option> freqOptions = new ArrayList<Option>(); if (context.getMode() != Mode.VIEW ) { for (int i = 1; i <= 10; i++) { freqOptions.add(new Option(i + "/" + mss.getMessage("DrugOrder.frequency.day"), String.valueOf(i), false)); } } frequencyWidget.setOptions(freqOptions); context.registerWidget(frequencyWidget); context.registerErrorWidget(frequencyWidget, frequencyErrorWidget); }
/** * Be aware it's called by the constructor. * * @param context * @param mss */ protected void createFrequencyWeekWidget(FormEntryContext context, MessageSourceService mss) { frequencyWeekWidget = new DropdownWidget(); frequencyWeekErrorWidget = new ErrorWidget(); // fill frequency drop down lists (ENTER, EDIT) List<Option> weekOptions = new ArrayList<Option>(); if (context.getMode() != Mode.VIEW ) { for (int i = 7; i >= 1; i--) { weekOptions.add(new Option(i + " " + mss.getMessage("DrugOrder.frequency.days") + "/" + mss.getMessage("DrugOrder.frequency.week") , String.valueOf(i), false)); } } frequencyWeekWidget.setOptions(weekOptions); context.registerWidget(frequencyWeekWidget); context.registerErrorWidget(frequencyWeekWidget, frequencyWeekErrorWidget); }
@Override protected void createFrequencyWidget(FormEntryContext context, MessageSourceService mss) { frequencyWidget = new DropdownWidget(); frequencyErrorWidget = new ErrorWidget(); // fill frequency drop down lists (ENTER, EDIT) List<OrderFrequency> orderFrequencies = Context.getOrderService().getOrderFrequencies(false); List<Option> freqOptions = new ArrayList<Option>(); if (context.getMode() != Mode.VIEW) { for (OrderFrequency orderFrequency : orderFrequencies) { freqOptions.add(new Option(orderFrequency.getConcept().getName().getName(), orderFrequency.getId() .toString(), false)); } if (!orderFrequencies.isEmpty()) { frequencyWidget.setInitialValue(orderFrequencies.get(0).getId()); } } frequencyWidget.setOptions(freqOptions); context.registerWidget(frequencyWidget); context.registerErrorWidget(frequencyWidget, frequencyErrorWidget); }
@Test public void UploadWidgetShouldProduceHtml(){ UploadWidget uw = new UploadWidget(); context.registerWidget(uw); Assert.assertEquals("<input type=\"file\" class=\"uploadWidget\" id=\"w1\" name=\"w1\"/>",uw.generateHtml(context)); }
@Test public void testGetWidgetByFieldName() { DropdownWidget widget = new DropdownWidget(); context.registerWidget(widget); String fieldName = context .getFieldName(widget); Widget w = context.getWidgetByFieldName(fieldName); assertNotNull(w); }
@Test public void testGetErrorDivIds() { DateWidget startDateWidget; ErrorWidget startDateErrorWidget; startDateWidget = new DateWidget(); startDateErrorWidget = new ErrorWidget(); context.registerWidget(startDateWidget); context.registerErrorWidget(startDateWidget, startDateErrorWidget); assertNotNull(context.getErrorDivIds()); }
@Test public void checkboxWidgetShouldProduceHtmlWithToggleDim() { ToggleWidget toggleWidget = new ToggleWidget("{id: 'hatColors', style: 'dim'}"); CheckboxWidget cw = new CheckboxWidget("Has a hat?", "true", toggleWidget.getTargetId(), toggleWidget.isToggleDim()); context.registerWidget(cw); Assert.assertEquals("<input type=\"checkbox\" id=\"w1\" name=\"w1\" value=\"true\" toggleDim=\"hatColors\"/><label for=\"w1\">Has a hat?</label><input type=\"hidden\" name=\"_w1\"/>", cw.generateHtml(context)); }
@Test public void checkboxWidgetShouldProduceHtmlWithToggleHide() { ToggleWidget toggleWidget = new ToggleWidget("{id: 'hatColors', style: 'hide'}"); CheckboxWidget cw = new CheckboxWidget("Has a hat?", "true", toggleWidget.getTargetId(), toggleWidget.isToggleDim()); context.registerWidget(cw); Assert.assertEquals("<input type=\"checkbox\" id=\"w1\" name=\"w1\" value=\"true\" toggleHide=\"hatColors\"/><label for=\"w1\">Has a hat?</label><input type=\"hidden\" name=\"_w1\"/>", cw.generateHtml(context)); }
@Test public void checkboxWidgetShouldProduceHtmlWithToggleSimple() { ToggleWidget toggleWidget = new ToggleWidget("hatColors"); CheckboxWidget cw = new CheckboxWidget("Has a hat?", "true", toggleWidget.getTargetId(), toggleWidget.isToggleDim()); context.registerWidget(cw); Assert.assertEquals("<input type=\"checkbox\" id=\"w1\" name=\"w1\" value=\"true\" toggleHide=\"hatColors\"/><label for=\"w1\">Has a hat?</label><input type=\"hidden\" name=\"_w1\"/>", cw.generateHtml(context)); }
@Test public void dropdownWidgetShouldProduceHtml() { DropdownWidget dw = new DropdownWidget(); context.registerWidget(dw); dw.addOption(new Option("Extra Large", "XL", false)); dw.addOption(new Option("Large", "L", true)); Assert.assertEquals("<select id=\"w1\" name=\"w1\"><option value=\"XL\">Extra Large</option><option value=\"L\" selected=\"true\">Large</option></select>", dw.generateHtml(context)); }
@Test public void checkboxWidgetShouldProduceHtml() { CheckboxWidget cw = new CheckboxWidget(); context.registerWidget(cw); Assert.assertEquals("<input type=\"checkbox\" id=\"w1\" name=\"w1\" value=\"true\"/><input type=\"hidden\" name=\"_w1\"/>", cw.generateHtml(context)); cw.setInitialValue("Something"); Assert.assertEquals("<input type=\"checkbox\" id=\"w1\" name=\"w1\" value=\"true\" checked=\"true\"/><input type=\"hidden\" name=\"_w1\"/>", cw.generateHtml(context)); cw.setLabel("This is a label"); Assert.assertEquals("<input type=\"checkbox\" id=\"w1\" name=\"w1\" value=\"true\" checked=\"true\"/><label for=\"w1\">This is a label</label><input type=\"hidden\" name=\"_w1\"/>", cw.generateHtml(context)); }