How to set all CheckBoxGroup checked by default?

I need to check all check box in a checkbox group by default.
I test to use its method select(String … items) and setValue (Set Value)
Noone works.

By the way, what difference between these method; I didn’t exaclty get as reading doc.

Hi Yichun, how’s it going?

Need you to clarify what exactly you meant cause, we presently do not have a CheckBoxGroup. If you meant
radio-button-group
, I’ll be happy to answer your questions.

Regards.

Hi Yichun, so someone on the team just helped me realize your question was most probably targeted at the Vaadin Framework, not the Vaadin Elements. This is the elements section of the Vaadin Forum, so how about I forward your question to the Framework team so they can help take a look as soon as someone is available?

Best regards.

Hi Yichun, I’ve forwarded your question to the Framework Team but of course, if you were able to find a solution before they get to it, that would be great too.

Hi, Victor

thanks for kind reply. I am using Vaadin 8, in which I can see a group for holding check boxes.

final CheckBoxGroup interests = new CheckBoxGroup<>(“Growing Interests”, Interest.getSet());

I hope all the boxes are checked by default. So I do the below, immediately after the above; However, it won’t take any impact. Why?

Interest.getCollection().forEach(x->interests.select(x));

I defined Interest as an enum to hold iterms etc

public enum Interest {

HERBS("Herbs"), VEGETABLES("Vegetables"), FRUITS("Fruits"), PLANTS("Plants"), FLOWERS("Flowers"), TREES("Trees");
private String text;

private Interest(String text) {
    this.text = text;
}

public String text() {
    return this.text;
}

public static Stream<String> getCollection() {
    return Arrays.asList(Interest.values()).stream().map(x -> x.text());
}

public static Set<String> getSet() {
    return getCollection().collect(Collectors.toSet());
    //return new HashSet<>(Arrays.asList(Interest.values()).stream().collect(Collectors.toList()));
    
}

public static String[] toArray() {
    return getCollection().toArray(size -> new String[size]

);
}

public static Interest retrieve(String text) {
    if ("".equals(text) || text == null) {
        return null;
    }
    return Arrays.asList(Interest.values()).stream().filter(x -> {
        return x.text().equals(text);
    }).collect(Collectors.toList()).get(0);
}

}

Hey Yichun,

only at in the train atm so I cannot confirm if this works, but try change the CheckBoxGroup to CheckBoxGroup and add an ItemCaptionGenerator so it displays the String values, maybe then you can use foreach.

Greetings,
Michael

Thank Michael.
You are right. It works now. I didn’t get why. It seems that it missed a triggering if don’t using caption generator.