如何预选 h:selectManyCheckbox
中的元素成分?我已经搜索了 f:selectItem
的属性标记但尚未找到如何预先选择此项目(即在调用站点时已勾选)。
最佳答案
value
h:selectManyCheckbox
的属性可以接受来自托管 bean 的字符串数组。您可以在初始化托管 bean 时直接为该数组设置默认值。
例如,在 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>
然后在 MBean 中:
public class MBean{
//Preselect the "Choice A" and "Choice C"
private String[] choice= {"A","C"};
//Getter and setter of choice
}
关于jsf - 预选项目 h :selectManyCheckbox,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6650327/