문제

I am creating a list of checkboxes on my visualforce page as follows

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

My items and productItems are set similarly to the examples in https://www.salesforce.com/us/developer/docs/pages/Content/pages_compref_selectOption.htm

Where or how can I set me values to have a default of true? I do not sea setting in the visualforce component apex:selectOptions or apex:selectCheckboxes for this.

Any help would be appreciated.

도움이 되었습니까?

해결책

Initialize your productItems in the controller, for example in the constructor.

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.

Think about it like that. Ideally the controller class should work on it's own. Maybe reused and called from another class, without any Visualforce context. So in pure apex you'd simply initialize the list ;)

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top