首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >JSF/SEAM:如何在表单中预先选择复选框

JSF/SEAM:如何在表单中预先选择复选框
EN

Stack Overflow用户
提问于 2009-11-24 22:38:13
回答 2查看 3.7K关注 0票数 2

我有一个表单,我必须预先选择一些复选框。使用jsf/seam怎么可能做到这一点?在普通html中,您只需将"checked“(或checked="checked")属性添加到复选框即可。但是对于f:SelectItem I我没有clue...also对象“selectItems”并没有为此提供任何设置器...

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2009-11-24 22:47:16

您需要像通常对每个UIInput组件所做的那样,在组件的value属性后面的属性中预置它们。您可以在bean的构造函数或初始化块中执行此操作。

下面是一个基本的例子:

代码语言:javascript
复制
<h:selectManyCheckbox value="#{bean.selectedItems}">
    <f:selectItems value="#{bean.selectItems}" />
</h:selectManyCheckbox>

Bean:

代码语言:javascript
复制
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.
}
票数 6
EN

Stack Overflow用户

发布于 2009-11-24 22:48:01

在渲染页面之前,填充您在"value“中使用的属性(例如,使用阶段侦听器)

代码语言:javascript
复制
<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>
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/1790473

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档