You need to sign in to do that
Don't have an account?
sivas
Select Options problem
I couldn't capture and display the options selected in the visualforce page. I include my controller and visualforce page. Intent is a custom object. Everything looks fine, don't know what i am missing.
public class intent{ String[] intent; public String[] getintent(){ return intent; } public void setintent(String[] intent){ this.intent = intent; } public list<SelectOption> getintents(){ list<Intent__c> custintents = new list<Intent__c>(); custintents = [SELECT Name FROM Intent__c order by CreatedDate ASC]; List<SelectOption> options = new List<SelectOption>(); for(Intent__c custintent : custintents){ options.add(new SelectOption(custintent.Name,custintent.Name)); } return options; } public PageReference Next(){ return null; } }
<apex:page controller="intent"> <apex:form id="form1"> <apex:selectCheckboxes value="{!intent}" onselect="{!intent}"> <apex:selectOptions value="{!intents}"> </apex:selectOptions> </apex:selectCheckboxes> <apex:commandButton action="{!Next}" value="Next" 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="{!intent}" var="c">a:{!c}</apex:dataList> </apex:outputPanel> </apex:facet> </apex:actionstatus> </apex:outputPanel> </apex:page>
Hi,
You are not instantiated the array of strings thats why you are not able to display the selected values.
Please replace with the following line.
public String[] intent = new String[]{};
All Answers
Hi,
You are not instantiated the array of strings thats why you are not able to display the selected values.
Please replace with the following line.
public String[] intent = new String[]{};
Thanks sivarajan. How silly of me to miss that part. I am going to mark your response as solution. I have a simple follow up question, when i change the tag from <apex:Checkboxes> to <apex:selectList>, its not working again. Bottom line is i should be able to select only one option thats why i wanted to use either selectList or selectRadio but its not working for both tags.
Thanks.
Hi Siva,
If you want to use Apex: selectRadio or SelectList then you should do the following changes in vf page and & Controller :
Controller :
Declare variable 'intent' as simple string (Remove the array). and also change the getter and setter method to remove the array.
Vf page :
Remove the data List and use Apex:outputText to print selected value.
Thanks sivarajan. I appreciate your help.