Viktoriia
Viktoriia

Reputation: 2400

How to add to the object of SelectManyCheckbox selected values?

I have an object of SelectManyCheckbox. For this object I set available values in the next way:

SelectManyCheckbox checkbox = new SelectManyCheckbox();

List<Double> selected = new ArrayList<Double>();//this will be used for setting selected values
List<SelectItem> items = new ArrayList<SelectItem>();//this will be used as available values

for (SomeObject av : listOfObjects)
            {
                SelectItem item = new SelectItem(av.getNumericValue(),
                        av.getValue());
                items.add(item);
                if (av.getDefault())
                {
                    selected.add(av.getNumericValue());
                }
            }

UISelectItems uiItems = new UISelectItems();
uiItems.setValue(items);
checkbox.getChildren().add(uiItems);
checkbox.setSelectedValues(new Double[selected.size()]);

But this way of setting of selected values does not work. Maybe someone know there is the source of the problem?

Upvotes: 1

Views: 527

Answers (1)

mrganser
mrganser

Reputation: 1113

Your Double[] is empty there, try converting the list to the array like this:

checkbox.setSelectedValues(selected.toArray(new Double[selected.size()]));

Upvotes: 1

Related Questions