1

我正在我的visualforce页面上创建一个复选框列表,如下所示

       <apex:selectCheckboxes value="{productItems}" layout="pageDirection">
            <apex:selectOptions value="{!items}"/><br/>  
       </apex:selectCheckboxes>  

我的 items 和 productItems 的设置类似于https://www.salesforce.com/us/developer/docs/pages/Content/pages_compref_selectOption.htm中的示例

我可以在哪里或如何将我的值设置为默认值为 true?我不在 visualforce 组件 apex:selectOptions 或 apex:selectCheckboxes 中设置这个。

任何帮助,将不胜感激。

4

1 回答 1

2

在控制器中初始化你productItems的,例如在构造函数中。

List<String> productItems = new List<String>(); // boring

List<String> productItems = new List<String>{'foo', 'bar', 'baz'}; // will have 
// these 3 checked assuming there are SelectOptions available with exactly same
// values.

这样想吧。理想情况下,控制器类应该独立工作。可能在没有任何 Visualforce 上下文的情况下重用并从另一个类调用。因此,在纯顶点中,您只需初始化列表;)

于 2014-01-26T08:40:15.397 回答