+ Start a Discussion

How can capture selectCheckBoxes selectOptions across rows?


I need a requirement to have checkboxes across rows (in a list). I need to capture the checked checkbox values in my controller.

I studied the example presented in the Visualforce Developer's Guide (selectCheckBoxes, selectOptions). It seems the sample works if all checkboxes are grouped in a single row. But when I try to have a single chexkbox per row, I can;'t get it to work.

Please advice. Thanks.

Here are my codes (based on the developer's guide). Please pardon the indentation.

My VF page:
<apex:page controller="sampleCon">
<apex:form >
<apex:pageBlock >
<apex:pageBlockTable value="{!items}" var="item">
<apex:column >
<apex:selectCheckboxes value="{!countries}">
<apex:selectOption value="{!item}"/>
<apex:commandButton value="Test" action="{!test}" rerender="out" status="status"/>
<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">{!c}</apex:dataList>

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


I found the solution from reading Sending inputCheckBox values to controller