我有一个表单,我必须预先选择一些复选框。使用jsf/seam怎么可能做到这一点?在普通html中,您只需将"checked“(或checked="checked")属性添加到复选框即可。但是对于f:SelectItem I我没有clue...also对象“selectItems”并没有为此提供任何设置器...
发布于 2009-11-24 22:47:16
您需要像通常对每个UIInput组件所做的那样,在组件的value属性后面的属性中预置它们。您可以在bean的构造函数或初始化块中执行此操作。
下面是一个基本的例子:
<h:selectManyCheckbox value="#{bean.selectedItems}">
<f:selectItems value="#{bean.selectItems}" />
</h:selectManyCheckbox>Bean:
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.
}发布于 2009-11-24 22:48:01
在渲染页面之前,填充您在"value“中使用的属性(例如,使用阶段侦听器)
<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>https://stackoverflow.com/questions/1790473
复制相似问题