function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
okaylah52okaylah52 

How can capture selectCheckBoxes selectOptions across rows?

Hi,

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:
Code:
<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:selectCheckboxes>
</apex:column>
</apex:pageBlockTable>
<br/>
<apex:commandButton value="Test" action="{!test}" rerender="out" status="status"/>
</apex:pageBlock>
</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">{!c}</apex:dataList>
</apex:outputPanel>
</apex:facet>
</apex:actionstatus>
</apex:outputPanel>
</apex:page>

 
My Controller:
Code:
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;
}
}

 

okaylah52okaylah52
I found the solution from reading Sending inputCheckBox values to controller
Thanks.