开发者

Preselect items in h:selectManyCheckbox

开发者 https://www.devze.com 2023-03-19 03:58 出处:网络
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 (

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

}


Add to your backing list or array objects that return true when comparing equals to the value of the SelectItems you want to preselect.

0

精彩评论

暂无评论...
验证码 换一张
取 消