开发者

Preselect items in h:selectManyCheckbox

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜