Hi, i wanto to populate a dropdownlist(or datadropdownlist) from java code.there is a method named getValue, this is ok but there is no method like get/setLabel, how can i get or set the label of the options from java side?
Regards.
If there are Accepted Answers, those will be shown by default. You can switch to 'All Replies' by selecting the tab below.
you can do so, by following steps:
a. fetch the control (dropdownlist/datadropdownlist) in java class
b. create an object of class Option (com.documentum.web.form.control.Option), like:
Option optionObj = new Option();
c. set the label and value for option (using setLabel and setValue method)
d. add option to dropdownlist / datadropdownlist control (using addOption method)
Or
Create list of Option objects
Use method setOptions to add list to dropdownlist or datadropdownlist control
Hi,
These are the utility methods I use for populating dropdowns and list boxes. Kindly change as required
public static void populateListBox(ListBox list, String[] labels, boolean isClearRequired) { list.setMutable(true); if (isClearRequired) list.clearOptions(); Option option = new Option(); option.setLabel(""); option.setValue(""); list.addOption(option); for (int i = 0; i < labels.length; i++) { if (isValidString(labels[i])) { option = new Option(); option.setLabel(labels[i]); option.setValue(labels[i]); list.addOption(option); } } list.setMutable(false); } //Comma seperated label and value to be provided public static void populateDropDown(DropDownList list, String label, String value) { list.setMutable(true); final String[] labels = label.split(","); final String[] values = value.split(","); Option option = null; for (int i = 0; i < labels.length; i++) { option = new Option(); option.setLabel(labels[i]); option.setValue(values[i]); list.addOption(option); } list.setMutable(false); } /** * Adds a special value as first item in the dropdown. This is used when you * want "Select" or blank string as first value. * * If isSpecialRequired is false then specialValue is ignored * * Also you can clean the dropdown before loading values * * */ public static void populateDropDown(DropDownList list, String[] values, boolean isSpecialRequired, String specialValue, boolean isClearRequired, boolean isSortRequired) { if (values != null) { list.setMutable(true); if (isSortRequired) Arrays.sort(values); if (isClearRequired) list.clearOptions(); Option option = null; if (isSpecialRequired && specialValue != null) { option = new Option(); option.setLabel(specialValue); option.setValue(specialValue); list.addOption(option); } for (int i = 0; i < values.length; i++) { if (isValidString(values[i])) { option = new Option(); option.setLabel(values[i]); option.setValue(values[i]); list.addOption(option); } } list.setMutable(false); } } public static void clearDropDown(DropDownList list) { list.setMutable(true); list.clearOptions(); list.setMutable(false); }