繁体   English   中英

预选 h:selectManyCheckbox 中的项目

[英]Preselect items in h:selectManyCheckbox

如何预选h:selectManyCheckbox组件中的元素? 我已经搜索了f:selectItem标记的属性,但还没有找到如何预先选择这个项目(即在调用站点时它已经被勾选)。

h:selectManyCheckboxvalue属性可以接受来自托管 bean 的字符串数组。 您可以在托管 bean 初始化时直接将默认值设置为该数组。

例如,在视图中:

<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>

然后在 MBean 中:

public class MBean{

    //Preselect the "Choice A" and "Choice C" 
    private String[] choice= {"A","C"};

    //Getter and setter of choice

}

添加到您的后备列表或数组对象,当比较等于您要预选的 SelectItems 的值时返回 true。

暂无
暂无

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

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