• 4512
  • NEWBIE
  • 0 Points
  • Member since 2009

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies

I am displaying a list of items using the selectcheckboxes in a manner virtually identical to the example from the VisualForce documentation on page 210 as reflected below.

 

I am interested in checking some of the checkboxes as they are displayed, without user input.  What code would need to be added to this example in order for my checkboxes to appear checked as they are being displayed?

 

Thanks in advance for your help.

 

Jeff

 

<!-- Page: --> <apex:page controller="sampleCon"> <apex:form> <apex:selectCheckboxes value="{!countries}" title="Choose a country"> <apex:selectOptions value="{!items}"/> </apex:selectCheckboxes><br/> <apex:commandButton value="Test" action="{!test}" rerender="out" status="status"/> </apex:form> <apex:outputPanel id="out"> <apex:actionstatus id="status" startText="testing..."> <apex:facet name="stop"> <apex:outputPanel> <p>You have selected:</p> <apex:dataList value="{!countries}" var="c">a:{!c}</apex:dataList> </apex:outputPanel> </apex:facet> </apex:actionstatus> </apex:outputPanel> </apex:page> /*** Controller: ***/ public class sampleCon { String[] countries = new String[]{}; public PageReference test() { return null; } public List<SelectOption> getItems() { List<SelectOption> options = new List<SelectOption>(); options.add(new SelectOption('US','US')); options.add(new SelectOption('CANADA','Canada')); options.add(new SelectOption('MEXICO','Mexico')); return options; } public String[] getCountries() { return countries; } public void setCountries(String[] countries) { this.countries = countries; } } Attributes

 

  • February 21, 2009
  • Like
  • 0