简体   繁体   English

预选 h:selectManyCheckbox 中的项目

[英]Preselect items in h:selectManyCheckbox

How do I preselect the elements in a h:selectManyCheckbox component?如何预选h:selectManyCheckbox组件中的元素? I've searched through the properties of the f:selectItem tag but not yet have found how to pre-select this item (ie it is ticked already when the site is called).我已经搜索了f:selectItem标记的属性,但还没有找到如何预先选择这个项目(即在调用站点时它已经被勾选)。

The value attribute of h:selectManyCheckbox can accept an array of string from the managed bean. h:selectManyCheckboxvalue属性可以接受来自托管 bean 的字符串数组。 You can directly set the default values to this array when the managed bean is initialized.您可以在托管 bean 初始化时直接将默认值设置为该数组。

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:然后在 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.添加到您的后备列表或数组对象,当比较等于您要预选的 SelectItems 的值时返回 true。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM