How do I preselect the elements in a h:selectManyCheckbox
component? I've searched through the properties of the f:selectItem
tag but not yet have found how to pre-select this item (i.e. it is ticked already when the site is called).
The value
attribute of h:selectManyCheckbox
can accept an array of string from the managed bean. You can directly set the default values to this array when the managed bean is initialized.
For example , in the view :
<h:selectManyCheckbox value="#{MBean.choice}">
<f:selectItem itemValue="A" itemLabel="Choice A" />
<f:selectItem itemValue="B" itemLabel="Choice B" />
<f:selectItem itemValue="C" itemLabel="Choice C"/>
<f:selectItem itemValue="D" itemLabel="Choice D" />
</h:selectManyCheckbox>
Then in the MBean :
public class MBean{
//Preselect the "Choice A" and "Choice C"
private String[] choice= {"A","C"};
//Getter and setter of choice
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With