You need to sign in to do that
Don't have an account?

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