[英]JSF/SEAM: How to pre-select checkboxes in a form
我有一个表格,我必须预先选择一些复选框。 jsf / seam怎么可能? 在纯HTML中,您只需将“ checked”(或checked =“ checked”)作为属性添加到复选框。 但是对于f:selectItems我一无所知...对象“ SelectItem”也没有为此提供任何设置器...
您需要像通常对每个UIInput
组件那样在组件的value
属性后面的属性中预置它们。 您可以在Bean的构造函数或初始化块中执行此操作。
这是一个基本的例子:
<h:selectManyCheckbox value="#{bean.selectedItems}">
<f:selectItems value="#{bean.selectItems}" />
</h:selectManyCheckbox>
豆角,扁豆:
private List<String> selectedItems; // +getter +setter.
private List<SelectItem> selectItems; // +getter.
public Bean() {
// Preset the selected items.
this.selectedItems = new ArrayList<String>();
this.selectedItems.add("valueToBePreselected1");
this.selectedItems.add("valueToBePreselected2");
// Those values should be exactly the same as one of the SelectItem values.
// I.e. the Object#equals() must return true for any of them.
}
在渲染页面之前填充您在“值”中使用的属性(例如,使用阶段侦听器)
<h:selectManyCheckbox value="#{selectManyCheckBoxBean.selectedItems}">
<f:selectItem itemLabel="India" itemValue="India" />
<f:selectItem itemLabel="China" itemValue="China" />
<f:selectItem itemLabel="Germany" itemValue="Germany" />
<f:selectItem itemLabel="USA" itemValue="USA" />
</h:selectManyCheckbox>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.