Question

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.

Was it helpful?

Solution

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 ;)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top