SelectDDMFormFieldTemplateContextContributor implements DDMFormFieldTemplateContextContributor { @Override public Map<String, Object> getParameters( DDMFormField ddmFormField, DDMFormFieldRenderingContext ddmFormFieldRenderingContext) { Map<String, Object> parameters = HashMapBuilder.<String, Object>put( "dataSourceType", ddmFormField.getDataSourceType() ).put( "multiple", getMultiple(ddmFormField, ddmFormFieldRenderingContext) ).build(); DDMFormFieldOptions ddmFormFieldOptions = ddmFormFieldOptionsFactory.create( ddmFormField, ddmFormFieldRenderingContext); parameters.put( "options", getOptions( ddmFormFieldOptions, ddmFormFieldRenderingContext.getLocale(), ddmFormFieldRenderingContext)); Locale displayLocale = LocaleThreadLocal.getThemeDisplayLocale(); if (displayLocale == null) { displayLocale = ddmFormFieldRenderingContext.getLocale(); } ResourceBundle resourceBundle = getResourceBundle(displayLocale); Map<String, String> stringsMap = new HashMap<>(); stringsMap.put( "chooseAnOption", LanguageUtil.get(resourceBundle, "choose-an-option")); stringsMap.put( "chooseOptions", LanguageUtil.get(resourceBundle, "choose-options")); stringsMap.put( "dynamicallyLoadedData", LanguageUtil.get(resourceBundle, "dynamically-loaded-data")); stringsMap.put( "emptyList", LanguageUtil.get(resourceBundle, "empty-list")); stringsMap.put("search", LanguageUtil.get(resourceBundle, "search")); parameters.put("strings", stringsMap); List<String> predefinedValue = getValue( getPredefinedValue(ddmFormField, ddmFormFieldRenderingContext)); if (predefinedValue != null) { parameters.put("predefinedValue", predefinedValue); } parameters.put( "value", getValue( GetterUtil.getString( ddmFormFieldRenderingContext.getValue(), "[]"))); return parameters; }  @Override Map<String, Object> getParameters(
		DDMFormField ddmFormField,
		DDMFormFieldRenderingContext ddmFormFieldRenderingContext);  }
@Test public void testGetParameters1() throws Exception { DDMFormField ddmFormField = new DDMFormField("field", "select"); ddmFormField.setProperty("dataSourceType", "data-provider"); DDMFormFieldRenderingContext ddmFormFieldRenderingContext = new DDMFormFieldRenderingContext(); ddmFormFieldRenderingContext.setLocale(LocaleUtil.US); ddmFormFieldRenderingContext.setValue("[\"value 1\"]"); _setUpDDMFormFieldOptionsFactory( ddmFormField, ddmFormFieldRenderingContext); SelectDDMFormFieldTemplateContextContributor spy = _createSpy(); Map<String, Object> parameters = spy.getParameters( ddmFormField, ddmFormFieldRenderingContext); Assert.assertTrue(parameters.containsKey("dataSourceType")); Assert.assertEquals("data-provider", parameters.get("dataSourceType")); Assert.assertTrue(parameters.containsKey("multiple")); Assert.assertEquals(false, parameters.get("multiple")); Assert.assertTrue(parameters.containsKey("options")); List<Object> options = (List<Object>)parameters.get("options"); Assert.assertEquals(options.toString(), 3, options.size()); Map<String, String> optionMap = (Map<String, String>)options.get(0); Assert.assertEquals("Label 1", optionMap.get("label")); Assert.assertEquals("value 1", optionMap.get("value")); optionMap = (Map<String, String>)options.get(1); Assert.assertEquals("Label 2", optionMap.get("label")); Assert.assertEquals("value 2", optionMap.get("value")); optionMap = (Map<String, String>)options.get(2); Assert.assertEquals("Label 3", optionMap.get("label")); Assert.assertEquals("value 3", optionMap.get("value")); List<String> value = (List<String>)parameters.get("value"); Assert.assertEquals(value.toString(), 1, value.size()); Assert.assertTrue(value.toString(), value.contains("value 1")); }
@Test public void testGetParameters2() throws Exception { DDMFormField ddmFormField = new DDMFormField("field", "select"); ddmFormField.setProperty("dataSourceType", "manual"); ddmFormField.setMultiple(true); DDMFormFieldRenderingContext ddmFormFieldRenderingContext = new DDMFormFieldRenderingContext(); ddmFormFieldRenderingContext.setLocale(LocaleUtil.US); LocalizedValue predefinedValue = new LocalizedValue(); predefinedValue.setDefaultLocale(LocaleUtil.US); predefinedValue.addString(LocaleUtil.US, "[\"value 2\",\"value 3\"]"); ddmFormField.setPredefinedValue(predefinedValue); _setUpDDMFormFieldOptionsFactory( ddmFormField, ddmFormFieldRenderingContext); SelectDDMFormFieldTemplateContextContributor spy = _createSpy(); Map<String, Object> parameters = spy.getParameters( ddmFormField, ddmFormFieldRenderingContext); Assert.assertTrue(parameters.containsKey("dataSourceType")); Assert.assertEquals("manual", parameters.get("dataSourceType")); Assert.assertTrue(parameters.containsKey("multiple")); Assert.assertEquals(true, parameters.get("multiple")); Assert.assertTrue(parameters.containsKey("options")); List<Object> options = (List<Object>)parameters.get("options"); Assert.assertEquals(options.toString(), 3, options.size()); Map<String, String> optionMap = (Map<String, String>)options.get(0); Assert.assertEquals("Label 1", optionMap.get("label")); Assert.assertEquals("value 1", optionMap.get("value")); optionMap = (Map<String, String>)options.get(1); Assert.assertEquals("Label 2", optionMap.get("label")); Assert.assertEquals("value 2", optionMap.get("value")); optionMap = (Map<String, String>)options.get(2); Assert.assertEquals("Label 3", optionMap.get("label")); Assert.assertEquals("value 3", optionMap.get("value")); List<String> predefinedValueParameter = (List<String>)parameters.get( "predefinedValue"); Assert.assertEquals( predefinedValueParameter.toString(), 2, predefinedValueParameter.size()); Assert.assertTrue( predefinedValueParameter.toString(), predefinedValueParameter.contains("value 2")); Assert.assertTrue( predefinedValueParameter.toString(), predefinedValueParameter.contains("value 3")); }