@Test public void testRefreshInputAddExistingNullOption() { when(field.getAddEmptyOption()).thenReturn(true); options.put(null, "null"); renderer.refreshInput(options, null); verify(field).getAddEmptyOption(); verify(translationService, never()).getTranslation(FormRenderingConstants.ListBoxFieldRendererEmptyOptionText); verify(optionsRenderer).setValues(options); verify(valueListBox).setAcceptableValues(any()); }
@Override protected void refreshInput(Map<TYPE, String> optionsValues, TYPE selectedValue) { List<TYPE> values = optionsValues.keySet().stream().collect(Collectors.toList()); if (field.getAddEmptyOption()) { if (!values.contains(null)) { values.add(0, null); optionsValues.put(null, translationService.getTranslation(FormRenderingConstants.ListBoxFieldRendererEmptyOptionText)); } else { Collections.swap(values, values.indexOf(null), 0); } } if (widgetList.getValue() == null && optionsValues.containsKey(selectedValue)) { widgetList.setValue(selectedValue); } optionsRenderer.setValues(optionsValues); widgetList.setAcceptableValues(values); }
AbstractListBoxFieldRenderer extends SelectorFieldRenderer<FIELD, OPTION, TYPE> implements RequiresValueConverter { @Override protected void refreshInput(Map<TYPE, String> optionsValues, TYPE selectedValue) { List<TYPE> values = optionsValues.keySet().stream().collect(Collectors.toList()); if (field.getAddEmptyOption()) { if (!values.contains(null)) { values.add(0, null); optionsValues.put(null, translationService.getTranslation(FormRenderingConstants.ListBoxFieldRendererEmptyOptionText)); } else { Collections.swap(values, values.indexOf(null), 0); } } if (widgetList.getValue() == null && optionsValues.containsKey(selectedValue)) { widgetList.setValue(selectedValue); } optionsRenderer.setValues(optionsValues); widgetList.setAcceptableValues(values); } }
AbstractListBoxFieldRenderer extends SelectorFieldRenderer<FIELD, OPTION, TYPE> implements RequiresValueConverter { @Override protected void refreshInput(Map<TYPE, String> optionsValues, TYPE selectedValue) { List<TYPE> values = optionsValues.keySet().stream().collect(Collectors.toList()); if (field.getAddEmptyOption()) { if (!values.contains(null)) { values.add(0, null); optionsValues.put(null, translationService.getTranslation(FormRenderingConstants.ListBoxFieldRendererEmptyOptionText)); } else { Collections.swap(values, values.indexOf(null), 0); } } if (widgetList.getValue() == null && optionsValues.containsKey(selectedValue)) { widgetList.setValue(selectedValue); } optionsRenderer.setValues(optionsValues); widgetList.setAcceptableValues(values); } AbstractListBoxFieldRenderer(TranslationService translationService); }
AbstractListBoxFieldRenderer extends SelectorFieldRenderer<FIELD, OPTION, TYPE> implements RequiresValueConverter { @Override protected void refreshInput(Map<TYPE, String> optionsValues, TYPE selectedValue) { List<TYPE> values = optionsValues.keySet().stream().collect(Collectors.toList()); if (field.getAddEmptyOption()) { if (!values.contains(null)) { values.add(0, null); optionsValues.put(null, translationService.getTranslation(FormRenderingConstants.ListBoxFieldRendererEmptyOptionText)); } else { Collections.swap(values, values.indexOf(null), 0); } } if (widgetList.getValue() == null && optionsValues.containsKey(selectedValue)) { widgetList.setValue(selectedValue); } optionsRenderer.setValues(optionsValues); widgetList.setAcceptableValues(values); } AbstractListBoxFieldRenderer(TranslationService translationService); @Override String getName(); abstract TYPE getEmptyValue(); @Override Converter getConverter(); }
AbstractListBoxFieldRenderer extends SelectorFieldRenderer<FIELD, OPTION, TYPE> implements RequiresValueConverter { @Override protected void refreshInput(Map<TYPE, String> optionsValues, TYPE selectedValue) { List<TYPE> values = optionsValues.keySet().stream().collect(Collectors.toList()); if (field.getAddEmptyOption()) { if (!values.contains(null)) { values.add(0, null); optionsValues.put(null, translationService.getTranslation(FormRenderingConstants.ListBoxFieldRendererEmptyOptionText)); } else { Collections.swap(values, values.indexOf(null), 0); } } if (widgetList.getValue() == null && optionsValues.containsKey(selectedValue)) { widgetList.setValue(selectedValue); } optionsRenderer.setValues(optionsValues); widgetList.setAcceptableValues(values); } AbstractListBoxFieldRenderer(TranslationService translationService); @Override String getName(); abstract TYPE getEmptyValue(); @Override Converter getConverter();  }