@Test public void testListBoxWithExistingDefaultValue() { when(field.getDefaultValue()).thenReturn(VAL_2); SelectorData<String> data = provider.getSelectorData(context); doTestVerifications(data); assertNotNull(data.getSelectedValue()); assertEquals(VAL_2, data.getSelectedValue()); }
@Override public SelectorData getSelectorData(FormRenderingContext context) { SelectorData data = new SelectorData<>(); Map<Object, String> values = new HashMap<>(); Object selectedValue = null; if (context.getModel() instanceof SelectorFieldBaseDefinition) { SelectorFieldBaseDefinition selector = (SelectorFieldBaseDefinition) context.getModel(); selectedValue = selector.getDefaultValue(); List<SelectorOption> options = selector.getOptions(); options.forEach(option -> values.put(option.getValue(), option.getText())); if (!values.containsKey(selectedValue)) { selectedValue = null; selector.setDefaultValue(null); } } data.setValues(values); data.setSelectedValue(selectedValue); return data; }
SelectorOptionsProvider implements SystemSelectorDataProvider { @Override public SelectorData getSelectorData(FormRenderingContext context) { SelectorData data = new SelectorData<>(); Map<Object, String> values = new HashMap<>(); Object selectedValue = null; if (context.getModel() instanceof SelectorFieldBaseDefinition) { SelectorFieldBaseDefinition selector = (SelectorFieldBaseDefinition) context.getModel(); selectedValue = selector.getDefaultValue(); List<SelectorOption> options = selector.getOptions(); options.forEach(option -> values.put(option.getValue(), option.getText())); if (!values.containsKey(selectedValue)) { selectedValue = null; selector.setDefaultValue(null); } } data.setValues(values); data.setSelectedValue(selectedValue); return data; } }
SelectorOptionsProvider implements SystemSelectorDataProvider { @Override public SelectorData getSelectorData(FormRenderingContext context) { SelectorData data = new SelectorData<>(); Map<Object, String> values = new HashMap<>(); Object selectedValue = null; if (context.getModel() instanceof SelectorFieldBaseDefinition) { SelectorFieldBaseDefinition selector = (SelectorFieldBaseDefinition) context.getModel(); selectedValue = selector.getDefaultValue(); List<SelectorOption> options = selector.getOptions(); options.forEach(option -> values.put(option.getValue(), option.getText())); if (!values.containsKey(selectedValue)) { selectedValue = null; selector.setDefaultValue(null); } } data.setValues(values); data.setSelectedValue(selectedValue); return data; }  }
SelectorOptionsProvider implements SystemSelectorDataProvider { @Override public SelectorData getSelectorData(FormRenderingContext context) { SelectorData data = new SelectorData<>(); Map<Object, String> values = new HashMap<>(); Object selectedValue = null; if (context.getModel() instanceof SelectorFieldBaseDefinition) { SelectorFieldBaseDefinition selector = (SelectorFieldBaseDefinition) context.getModel(); selectedValue = selector.getDefaultValue(); List<SelectorOption> options = selector.getOptions(); options.forEach(option -> values.put(option.getValue(), option.getText())); if (!values.containsKey(selectedValue)) { selectedValue = null; selector.setDefaultValue(null); } } data.setValues(values); data.setSelectedValue(selectedValue); return data; }  @Override String getProviderName(); @Override SelectorData getSelectorData(FormRenderingContext context); }
SelectorOptionsProvider implements SystemSelectorDataProvider { @Override public SelectorData getSelectorData(FormRenderingContext context) { SelectorData data = new SelectorData<>(); Map<Object, String> values = new HashMap<>(); Object selectedValue = null; if (context.getModel() instanceof SelectorFieldBaseDefinition) { SelectorFieldBaseDefinition selector = (SelectorFieldBaseDefinition) context.getModel(); selectedValue = selector.getDefaultValue(); List<SelectorOption> options = selector.getOptions(); options.forEach(option -> values.put(option.getValue(), option.getText())); if (!values.containsKey(selectedValue)) { selectedValue = null; selector.setDefaultValue(null); } } data.setValues(values); data.setSelectedValue(selectedValue); return data; }  @Override String getProviderName(); @Override SelectorData getSelectorData(FormRenderingContext context);  }