在h:selectManyCheckbox中预选项目 [英] Preselect items in h:selectManyCheckbox
本文介绍了在h:selectManyCheckbox中预选项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何预选h:selectManyCheckbox
组件中的元素?我已经搜索了f:selectItem
标记的属性,但还没有找到如何预选择此项目的方法(即,在调用该网站时已将其选中).
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).
推荐答案
h:selectManyCheckbox
的value
属性可以接受来自托管bean的字符串数组.您可以在初始化托管Bean时直接将默认值设置为此数组.
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.
例如,在视图中:
<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
}
这篇关于在h:selectManyCheckbox中预选项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文